System.IO.FileLoadException with XNA

本文关键字:XNA with FileLoadException IO System | 更新日期: 2023-09-27 18:19:16

我使用的是Xna 3.0 (c# 4.0),在编译SharpDevelopPortable中的空白模板后,我得到了这个错误:

System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
   at Test_XNA.Game1..ctor()
   at Test_XNA.Program.Main() in c:'Users'%username%'Documents'Stuff'SharpDevelopPortable'Data'SharpDevelop Projects'Test_XNA'Test_XNA'Program.cs:line 9

这强调:

using System;
namespace Test_XNA
{
    static class Program
    {
        static void Main()
        {
            Game1 game = new Game1();  // <-- This line is highlighted 
            game.Run();
        }
    }
}
重要的是要注意我的Xna版本和c#版本是不同的。另外,我不是管理员,这就是我使用Xna 3.0的原因。我还收到了这个警告:

Found conflicts between different versions of the same dependent assembly. (MSB3247)

虽然我不确定这是什么意思。

System.IO.FileLoadException with XNA

根据这个优秀的答案,你必须找到你的app.config文件,并将useLegacyV2RuntimeActivationPolicy="true"属性添加到你的startup标签:

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>