1

My code:

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
            }
        }
    }
}

Program.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
        }        
    }
}

Exception details:

Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

So how can I get this code to work?

Mihai Bratulescu
  • 1,915
  • 3
  • 27
  • 43

1 Answers1

1

From Msdn useLegacyV2RuntimeActivationPolicy is for,

Specifies whether to enable the .NET Framework 2.0 runtime activation policy or to use the .NET Framework 4 activation policy.

In the App.confiig , just check useLegacyV2RuntimeActivationPolicy is true or not. It should be True.

<configuration> 
  <startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
  </startup> 
</configuration> 
Thilina H
  • 5,754
  • 6
  • 26
  • 56