简体   繁体   English

Monogame模板在使用System.TypeInitializationException启动时崩溃

[英]Monogame template crashes on launch with System.TypeInitializationException

Attempting to run this program on Windows 尝试在Windows上运行此程序

#region Using Statements
using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Input;

#endregion

namespace asdf
{
public class Game1 : Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;        

    public Game1() //Exception raised points to here
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";              
        graphics.IsFullScreen = true;       
    }
    protected override void Initialize()
    {
        base.Initialize();
    }
    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
    }
    protected override void Update(GameTime gameTime)
    {
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
        {
            Exit();
        }       
        base.Update(gameTime);
    }
    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
        base.Draw(gameTime);
    }
}
}

Raises the following exception 引发以下异常

Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: /tmp/install/lib/libgdiplus.so
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x000cc] in C:\cygwin\sources\mono\mcs\class\System.Drawing\System.Drawing\gdipFunctions.cs:127
  --- End of inner exception stack trace ---
  at System.Drawing.Icon.get_Handle () [0x00020] in C:\cygwin\sources\mono\mcs\class\System.Drawing\System.Drawing\Icon.cs:646
  at (wrapper remoting-invoke-with-check) System.Drawing.Icon:get_Handle ()
  at OpenTK.Platform.Windows.WinGLNative.set_Icon (System.Drawing.Icon value) [0x00000] in <filename unknown>:0
  at OpenTK.NativeWindow.set_Icon (System.Drawing.Icon value) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.OpenTKGameWindow.Initialize () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.OpenTKGameWindow..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.OpenTKGamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.Game..ctor () [0x00000] in <filename unknown>:0
  at asdf.Program.Main (System.String[] arrayargs) [0x00000] in <
filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: /tmp/install/lib/libgdiplus.so
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x000cc] in C:\cygwin\sources\mono\mcs\class\System.Drawing\System.Drawing\gdipFunctions.cs:127
  --- End of inner exception stack trace ---
  at System.Drawing.Icon.get_Handle () [0x00020] in C:\cygwin\sources\mono\mcs\class\System.Drawing\System.Drawing\Icon.cs:646
  at (wrapper remoting-invoke-with-check) System.Drawing.Icon:get_Handle ()
  at OpenTK.Platform.Windows.WinGLNative.set_Icon (System.Drawing.Icon value) [0x00000]in <filename unknown>:0
  at OpenTK.NativeWindow.set_Icon (System.Drawing.Icon value) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.OpenTKGameWindow.Initialize () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.OpenTKGameWindow..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.OpenTKGamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.Game..ctor () [0x00000] in <filename unknown>:0
  at asdf.Program.Main (System.String[] arrayargs) [0x00000] in <filename unknown>:0

When run in Mono. 在Mono中运行时。

I have tried: 我努力了:

  • Reinstalling Mono 重新安装Mono

  • Reinstalling Monogame 重新安装Monogame

  • Reinstalling Xamarin Studio 重新安装Xamarin Studio

  • Updating windows 更新视窗

and the error has remained unchanged. 该错误保持不变。

This error does not occur when using SFML.Net in place of monogame 当使用SFML.Net代替monogame时,不会发生此错误

The whole solution can be found here 整个解决方案可以在这里找到

Fix: 固定:

Make sure there aren't any incorrect mappings in the mono config file, ie remove any lines that look like this: 确保单声道配置文件中没有任何不正确的映射,即删除看起来像这样的所有行:

<dllmap dll="gdiplus" target="whatever" />
<dllmap dll="gdiplus.dll" target="whatever" />

Explanation: 说明:

If you look at the exception detail you'll most likely find an underlying System.DllNotFoundException being thrown because the parent Game class contains references to System.Drawing.GDIPlus which is exposed through gdiplus.dll . 如果您查看异常详细信息,则很可能会发现抛出了底层System.DllNotFoundException ,因为父Game类包含对通过gdiplus.dll公开的System.Drawing.GDIPlus引用。 gdiplus.dll is a core .NET Framework library so it should already be in your GAC. gdiplus.dll是一个核心.NET Framework库,因此它应该已经在您的GAC中。 The most common reason for being unable to load this with cross-platform frameworks like Mono is an invalid DLL mapping. 无法通过Mono等跨平台框架加载此文件的最常见原因是无效的DLL映射。

This is a Mono bug: https://bugzilla.xamarin.com/show_bug.cgi?id=8309 这是一个Mono错误: https//bugzilla.xamarin.com/show_bug.cgi?id = 8309

Solution: in "C:\\Program Files (x86)\\Mono-3.2.3\\etc\\mono\\config", locate and delete the following lines: 解决方案:在“ C:\\ Program Files(x86)\\ Mono-3.2.3 \\ etc \\ mono \\ config”中,找到并删除以下几行:

<dllmap dll="gdiplus" target="/tmp/install/lib/libgdiplus.so" />
<dllmap dll="gdiplus.dll" target="/tmp/install/lib/libgdiplus.so" />

I can verify that this fixes the issue. 我可以验证是否可以解决此问题。

I would also suggest pinging on the bug report linked above to increase the chances of getting a fix in the near future. 我还建议对上面链接的错误报告执行ping操作,以增加在不久的将来获得修复的机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM