Search code examples
c#raspberry-pimonogpio

FileNotFoundException using GPIO NuGet on Raspberry Pi


I am trying to run this tutorial on my Raspberry Pi 4 Model B with mono via Remote-Desktop. The application runs on .NET Framework 4.8.

While other simple executables (also with GUI) run smooth, this BlinkTutorial always quits with the following exception:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Device.Gpio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
File name: 'System.Device.Gpio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'System.Device.Gpio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
File name: 'System.Device.Gpio, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Obviously it has something to do with the GPIOs. I am relatively new to C# and this is my first time using a NuGet-Package (to access the GPIOS). I am mentioning this because - even if I don't think so - maybe there a chance I did something wrong while adding it to my project? Also I am surprised that there is no site note in the official tutorial about this Exception. Maybe there is an easy fix and I am just blind?

I already found this article leading to this solution but I honestly don't really get the hang of it. Is the solution written somewhere there? Can someone please explain it a bit more beginner-friendly?

Thanks in approach, I am really looking foreward to learn from you all!


Solution

  • Finally, I have been able to find a workaround:

    Instead of using .NET Framework 4.8 and mono I now use .NET 6 and deploy my application specifically for Linux-arm. If you are a beginner like me, I can recommend this Tutorial. You can follow it step by step. Note that Step 3 is not mandatory. Also, you will have to adjust ./HelloWorld to your own "path"/"ApplicationName".

    So far I noticed the following downsides with this solution.

    1. You now always have to use the following bash command before running the app for the first time, or else it won't be able to run:

      chmod +x HelloWorld

    2. The process of deploying the application, copying it to your raspy, and doing the above-mentioned bash command takes a little bit of time, which can be annoying while debugging. I guess that's the cost of using C# on a Linux environment.

    For me, the solution works out pretty well and I can finally continue learning about GPIOs. I hope this will help other beginners in the future since there are several guides but only this one worked out for my specific problem.

    I would be glad if someone with more experience approved my solution or adds missing information.

    Thanks in advance!

    Edit: improved readability