Controller.ActiveDevice Issue with Keboard HID Device

I have tried the following code on my G80TH that I purchased last week
(after updating the firmware to the latest) and all 3 throw an “An
unhandled exception of type ‘System.InvalidOperationException’ occured
in GHI.Usb.dll” error:

Cdc vsp = new Cdc();
Controller.ActiveDevice = vsp;

Mouse mouse = new Mouse();
Controller.ActiveDevice = mouse;

Keyboard kb = new Keyboard();
Controller.ActiveDevice = kb;

From the FEZ Config tool:

Firmware (TinyCLR) version information:
4.3.8.1 on this computer.
4.3.8.1 on this device.

The Firmware (TinyCLR) is up to date. <<<
Please wait for the device to reboot… Done.

All GHI references (GHI.Pins and GHI.Usb) are both version 4.3.8.1.

Other references are Microsoft.Spot.Hardware,
Microsoft.Spot.Hardware.Usb, and Microsoft.Spot.Native, all v4.3.1.0
and mscorlib v4.3.1.0.

Any ideas why this won’t work? I just want to stand up a USB HID Keyboard.

Hi @ C0demnky, welcome to the forum

Can you tell us what line the exception is thrown?

Can you tell us why you want to swap ActiveDevice like that? (I have a theory that these are asynchronous calls and the swap is happening too fast as the background task hasn’t finished. If you want to test this, add a thread.sleep(1000) or something between the calls and see if that changes behaviour)