gpt4 book ai didi

c# - Monogame 模板在启动时崩溃并出现 System.TypeInitializationException

转载 作者:可可西里 更新时间:2023-11-01 10:37:03 25 4
gpt4 key购买 nike

试图在 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);
}
}
}

引发以下异常

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

在 Mono 中运行时。

我试过:

  • 重新安装 Mono

  • 重新安装 Monogame

  • 重新安装 Xamarin Studio

  • 更新窗口

并且错误保持不变。

使用 SFML.Net 代替 monogame 时不会出现此错误

可以找到整个解决方案here

最佳答案

修复:

确保单声道配置文件中没有任何不正确的映射,即删除任何看起来像这样的行:

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

解释:

如果您查看异常详细信息,您很可能会发现底层 System.DllNotFoundException 被抛出,因为父 Game 类包含对 System 的引用。通过gdiplus.dll公开的Drawing.GDIPlusgdiplus.dll 是核心 .NET Framework 库,因此它应该已经在您的 GAC 中。无法使用 Mono 等跨平台框架加载它的最常见原因是无效的 DLL 映射。

关于c# - Monogame 模板在启动时崩溃并出现 System.TypeInitializationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19757784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com