简体   繁体   English

在 Raspberry Pi 上使用 GPIO NuGet 的 FileNotFoundException

[英]FileNotFoundException using GPIO NuGet on Raspberry Pi

I am trying to runthis tutorial on my Raspberry Pi 4 Model B with mono via Remote-Desktop.我正在尝试通过远程桌面在带有单声道的 Raspberry Pi 4 Model B 上运行教程。 The application runs on .NET Framework 4.8.该应用程序在 .NET Framework 4.8 上运行。

While other simple executables (also with GUI) run smooth, this BlinkTutorial always quits with the following exception:虽然其他简单的可执行文件(也带有 GUI)运行顺利,但这个 BlinkTutorial 总是退出,但出现以下异常:

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.显然它与GPIO有关。 I am relatively new to C# and this is my first time using a NuGet-Package (to access the GPIOS).我对 C# 比较陌生,这是我第一次使用 NuGet-Package(访问 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!感谢您的到来,我真的很期待向大家学习!

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.我现在使用 .NET 6 并专门为 Linux-arm 部署我的应用程序,而不是使用 .NET Framework 4.8 和 mono。 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.请注意,步骤 3 不是强制性的。 Also, you will have to adjust ./HelloWorld to your own "path"/"ApplicationName" .此外,您必须将./HelloWorld调整为您自己的"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:您现在必须在第一次运行应用程序之前使用以下 bash 命令,否则它将无法运行:

    chmod +x HelloWorld 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.部署应用程序、将其复制到您的 raspy 以及执行上述 bash 命令的过程需要一点时间,这在调试时可能会很烦人。 I guess that's the cost of using C# on a Linux environment.我想这就是在 Linux 环境中使用 C# 的成本。

For me, the solution works out pretty well and I can finally continue learning about GPIOs.对我来说,这个解决方案效果很好,我终于可以继续学习 GPIO。 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编辑:提高可读性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM