【问题标题】:Windows Forms Aplication File Load Exception [duplicate]Windows 窗体应用程序文件加载异常 [重复]
【发布时间】:2013-12-10 08:33:56
【问题描述】:

我的代码:

Listener.cs:

namespace ListenerNameSpace
{

    class Listener
    {
        Device [] gamepad;

        public Listener() {     }

        public void initializeGamePad()
        {
            int i = 0;
            gamepad = new Device[10];//max 10 gamepads possible due to limited USB ports

            foreach (DeviceInstance di in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly))
            {
                gamepad[i++] = new Device(di.InstanceGuid);//save all gamepads conected
            }

            if (i == 0)//no gamepads detected
                MessageBox.Show("No gamepad detected, please connect gamepad!");
            else
            {
                //do something is a gamepad is detected
            }
        }
    }
}

程序.cs:

using ListenerNameSpace;

namespace Windows_8_gamepad_UI
{
    static class Program
    {        
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            new Listener().initializeGamePad();//I get the exception here
        }        
    }
}

异常详情:

混合模式程序集是针对运行时的“v1.1.4322”版本构建的,如果没有额外的配置信息,则无法在 4.0 运行时中加载。

那么我怎样才能让这段代码工作呢?

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    来自MsdnuseLegacyV2RuntimeActivationPolicy是为了,

    指定是否启用 .NET Framework 2.0 运行时激活 策略或使用 .NET Framework 4 激活策略。

    App.confiig 中,只需检查 useLegacyV2RuntimeActivationPolicy 是否为真。 应该是True

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-11
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多