question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.Device.Gpio does not work on Mono

See original GitHub issue

When using SPI and other protocols on Mono the Windows type is being loaded and fails to load because some fields use WinRT types which don’t exist on Linux.

The workaround or quick fix is to replace new WindowsSpiDevice(...) with Activator.CreateInstance(Type.GetType(...), ...) - I’m currently investigating if this is a Mono issue or if there is any better solution to fix this. It should also be fixed for other protocols not just SPI.

Environment.OSVersion.Platform: Unix

Unhandled Exception:
System.TypeLoadException: Could not load type of field 'System.Device.Spi.Windows10SpiDevice:_winDevice' (1)                                       due to: Could not load file or assembly 'Windows.Devices.DevicesLowLevelContract, Version=3.0.0.0, Culture=ne                                      utral, PublicKeyToken=null' or one of its dependencies.
  at gpio_test.Program.Main (System.String[] args) [0x00044] in <3861456bb5704006a45ca22f1003fbbd>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type of field 'System.Device.Spi.                                      Windows10SpiDevice:_winDevice' (1) due to: Could not load file or assembly 'Windows.Devices.DevicesLowLevelCo                                      ntract, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
  at gpio_test.Program.Main (System.String[] args) [0x00044] in <3861456bb5704006a45ca22f1003fbbd>:0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jkoritzinskycommented, May 28, 2020

The way to migrate is to remove all references to winmds and System.Runtime.WindowsRuntime and System.Runtime.InteropServices.WindowsRuntime and instead just reference the Microsoft.Windows.SDK.NET package.

0reactions
jkoritzinskycommented, May 28, 2020

By the release of .NET 5 or 6, there should be a way to reference the package implicitly when targeting Windows to reduce the deployment size.

If you find any issues, I suggest reporting them at https://github.com/microsoft/cswinrt.

Read more comments on GitHub >

github_iconTop Results From Across the Web

(Raspbian + C# + Mono) Type initializer for 'System.Device ...
Device.Gpio has not been deeply tested against mono, because it is mostly targeting .NET Core. .NET Framework support is for Windows.
Read more >
GPIO on Mono / C# - Raspberry Pi Forums
Just wanted to put a link to a post, for anyone using Mono / C#, I have converted the Python file based GPIO...
Read more >
GpioController.OpenPin Method (System.Device.Gpio)
Opens a pin in order for it to be ready to use. The driver attempts to open the pin without changing its mode...
Read more >
System.Device.Gpio 1.1.0-prerelease.20153.1
The System.Device.Gpio package supports general-purpose I/O (GPIO) pins, PWM, I2C, SPI and related interfaces for interacting with low level ...
Read more >
RaspberryIO - Pi's hardware access from .NET
For Debian Stretch. Running .NET Core 3.1; Usage. Run the app on the raspberry. Obtaining Board and System Information; Using the GPIO Pins....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found