【问题标题】:OpenGL4Net System.BadImageFormatExceptionOpenGL4Net System.BadImageFormatException
【发布时间】:2016-08-08 18:13:20
【问题描述】:

后续行动: OpenGL4Net WM_PAINT does not exist?

我还在密切关注:https://sourceforge.net/p/ogl4net/wiki/Tutorials

目前的程序:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenGL4NET;

namespace pads2
{
    class Program : Form
    {
        private const int WM_PAINT = 15;
        RenderingContext rc;

        static void Main(string[] args)
        {
            Program program = new Program();
            program.Init();
            Application.Run(program);
        }

        // required for open GL
        void Init()
        {
            rc = RenderingContext.CreateContext(this);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        }

        void Render()
        {
            gl.Clear(GL.COLOR_BUFFER_BIT);

            // here is the right place to draw all your scene

            rc.SwapBuffers();
        }

        // change window size
        protected override void OnSizeChanged(EventArgs e)
        {
            gl.Viewport(0, 0, ClientSize.Width, ClientSize.Height);
            // projection matrix may also need adjusting
        }

        // required for open GL
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_PAINT: Render(); break;
                default: base.WndProc(ref m); break;
            }
        }
    }
}

问:如果我正确实施了教程,对于program.Init();线上的错误System.BadImageFormatException,我该怎么办?

另外:

附加信息:无法加载文件或程序集 'OpenGL4Net, Version=4.3.37.24,Culture=neutral,PublicKeyToken=null' 或其之一 依赖关系。试图加载一个不正确的程序 格式。

这可能是由于警告:

项目的处理器架构不匹配 正在构建的“MSIL”和参考的处理器架构 “OpenGL4Net”、“AMD64”。这种不匹配可能会导致运行时失败。 请考虑更改您的目标处理器架构 通过配置管理器进行项目,以便对齐处理器 您的项目和参考之间的体系结构,或采取 依赖于具有匹配处理器架构的参考 您项目的目标处理器架构。

但是根据:

How do I fix the Visual Studio compile error, "mismatch between processor architecture"?

这应该不是问题。下载 OpenGL4Net DLL 时只有(32 位或 64 位)位选项。

鉴于 Microsoft 中间语言与处理器不同,我尝试在发布模式而不是调试模式下运行,但没有任何区别。

【问题讨论】:

    标签: c# .net opengl dll compiler-errors


    【解决方案1】:

    您在编译时使用什么构建配置?你下载的是什么版本的OpenGL4Net? 32 位还是 64 位版本?

    尝试设置构建配置以匹配引用程序集的预期目标 CPU(因此,32 位或 64 位,取决于 OpenGL4Net 的下载)。

    详情请见C# compiling for 32/64 bit, or for any cpu?

    【讨论】:

    • 它在“调试”(已尝试“发布”)和“任何 CPU”中。我刚刚在构建配置中创建了一个专门的“64 位 CPU”,它工作正常!似乎 VS 并不默认为您的 CPU 和操作系统设置的 CPU 类型。 | Discworld - Sam Vimes - “做对是一种解脱,即使你知道你只有通过尝试所有可能的方法来犯错。”
    猜你喜欢
    • 2016-12-14
    • 1970-01-01
    • 2017-07-07
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多