Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Device.Gpio does not work on Mono #1089

Closed
krwq opened this issue May 27, 2020 · 6 comments · Fixed by #1095
Closed

System.Device.Gpio does not work on Mono #1089

krwq opened this issue May 27, 2020 · 6 comments · Fixed by #1095
Assignees
Labels
bug Something isn't working

Comments

@krwq
Copy link
Member

krwq commented May 27, 2020

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
@krwq krwq added the bug Something isn't working label May 27, 2020
@krwq krwq self-assigned this May 27, 2020
@krwq
Copy link
Member Author

krwq commented May 27, 2020

Just got info from Mono people, the better way to workaround it is moving constructor to a new method marked as [MethodImpl(MethodImplOptions.NoInlining)]

@jkoritzinsky
Copy link
Member

As a heads up per dotnet/runtime#35318, usage of WinRT types should move to the new C#/WinRT-based projections via the Microsoft.Windows.SDK.NET package when targeting .NET 5. (dotnet/runtime#36715 removes support for the built-in projection system)

@krwq
Copy link
Member Author

krwq commented May 28, 2020

@jkoritzinsky do you have any example of any project transitioning, I'm not sure I'm following what's the work we should do 😄

@jkoritzinsky
Copy link
Member

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.

@krwq
Copy link
Member Author

krwq commented May 28, 2020

That sounds simple enough, thanks for the heads up, I'll let you know should we have any questions

@jkoritzinsky
Copy link
Member

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.

@krwq krwq closed this as completed in #1095 Jun 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants