0

I'm trying to use a joystick in my C# WPF application using directX (using Microsoft.DirectX.DirectInput;), but for some odd reason I keep getting an error in the first line where I try to detect all the connected devices. All I have in my application so far is the following line of code in the contructor:

DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);

The error is as follows:

Error type: XamlParseException was unhandled.

Error Message: "The invocation of the constructor on type 'JoystickTest.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'."

I'm working off this example I found online: http://www.codeproject.com/KB/directx/joystick.aspx

My current setup is WPF, C#, .NET 4.0, and Windows 7 64-bit

Petezah
  • 1,465
  • 4
  • 26
  • 30

1 Answers1

0

Late to the party here but the issue is actually a bit deeper than what it says. It can't initalize because you are using the DirectInput assembly (1.x) which puts your application into mixed-mode assemblies. You need to add this to the bottom of your app.config's Configuration node. Last, or it'll continue to error from my experiences.

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
</startup>

Key component is useLegacyV2RuntimeActivationPolicy="true" -- this allows your app to use the older assemblies required.

erodewald
  • 1,815
  • 20
  • 45