C# RLNET/OPENTK System.MissingMethodException during run-tim



我正在尝试使用 RLNET 库在 c# 中制作一个小型 2D 游戏。RLNET 库将 OpenTK 作为依赖项,因此我使用 Visual Studio 中的 NuGet 包管理器将最新版本的 RLNET 和 OpenTK 添加到我的项目中。我正在按照一个教程解释如何使用这些库。但是,当我开始运行代码时,我在运行时遇到了MissingMethodException。

我跟随的教程在这里:https://roguesharp.wordpress.com/2016/03/02/roguesharp-v3-tutorial-creating-the-project/

"解决方案资源管理器"在"引用"下拉列表下显示项目中包含的两个库。我还将它们包含在我的代码中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RLNET;
using OpenTK;
namespace Rouge_Game
{
class Program
{
private static readonly int _screenWidth = 100;
private static readonly int _screenHeight = 70;
private static RLRootConsole _rootConsole;
static void Main(string[] args)
{
// This must be the exact name of the bitmap font file we are using or it will error.
string fontFileName = "terminal8x8.png";
// The title will appear at the top of the console window
string consoleTitle = "RougeSharp V3 Tutorial - Level 1";
// Tell RLNet to use the bitmap font that we specified and that each tile is 8 x 8 pixels
_rootConsole = new RLRootConsole(fontFileName, _screenWidth, _screenHeight,
8, 8, 1f, consoleTitle);
// Set up a handler for RLNET's Update event
_rootConsole.Update += OnRootConsoleUpdate;
// Set up a handler for RLNET's Render event
_rootConsole.Render += OnRootConsoleRender;
// Begin RLNET's game loop
_rootConsole.Run();
}
// Event handler for RLNET's Update event
private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e)
{
_rootConsole.Print(10, 10, "It worked!", RLColor.White);
}
// Event handler for RLNET's Render event
private static void OnRootConsoleRender(object sender, UpdateEventArgs e)
{
// Tell RLNET to draw the console that we set
_rootConsole.Draw();
}
}
}

代码中出现运行时错误的部分如下:

// Event handler for RLNET's Render event
private static void OnRootConsoleRender(object sender, UpdateEventArgs e)
{
// Tell RLNET to draw the console that we set
_rootConsole.Draw();
}

当我运行项目时,它编译没有错误并且程序启动,但随后抛出此异常:

System.MissingMethodException
HResult=0x80131513
Message=Method not found: 'Void 
OpenTK.Graphics.OpenGL.GL.BlendFunc(OpenTK.Graphics.OpenGL.BlendingFactorSrc, OpenTK.Graphics.OpenGL.BlendingFactorDest)'.
Source=RLNET
StackTrace:
at RLNET.RLRootConsole.Draw()
at Rouge_Game.Program.OnRootConsoleRender(Object sender, UpdateEventArgs e) in C:UserspjmulsourcereposRouge GameRouge GameProgram.cs:line 45
at RLNET.RLRootConsole.window_RenderFrame(Object sender, FrameEventArgs e)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at OpenTK.GameWindow.OnRenderFrame(FrameEventArgs e)
at OpenTK.GameWindow.RaiseRenderFrame(Double elapsed, Double& timestamp)
at OpenTK.GameWindow.DispatchRenderFrame()
at OpenTK.GameWindow.Run(Double updates_per_second, Double frames_per_second)
at OpenTK.GameWindow.Run(Double updateRate)
at RLNET.RLRootConsole.Run(Double fps)
at Rouge_Game.Program.Main(String[] args) in 
C:UserspjmulsourcereposRouge GameRouge GameProgram.cs:line 32

我不明白这个错误,但是当我使用Visual Studio内置的对象查看器时,当我打开OpenTK.dll时,我可以找到"丢失"功能。非常感谢有关如何解决此错误的任何建议。我还要感谢任何花时间提前帮助我的人。

OpenTK 的 3.x 分支有问题。尝试将您的 OpenTK 软件包降级回 2.x,它将起作用。

最新更新