我想做的是
我正在尝试创建一个库(Arduino.dll),通过笔记本电脑(Windows10)与蓝牙设备进行交互。此库用于桌面应用程序。为此,我必须同时引用Windows.winmd和System.Runtime.WindowsRuntime。
什么在起作用
我确实编写了这个库,并在一个控制台应用程序上测试了它,该应用程序位于同一个解决方案中的另一个项目上。为了使其正常工作,我必须在测试项目中引用该项目和Windows.winmd。请注意,这个测试项目用于测试我的所有库,因此它被严重操纵,多年来我一直在修改设置。
什么不起作用
我完成了dll的编写,并希望在我的桌面应用程序中使用它。因此,我在测试项目中引用了Arduino.dll和Windows.winmd,期望以相同的方式工作。不幸的是,在运行应用程序时,当为Arduino.dll实例化类时,我得到了一个“未找到的dll”:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in LuxAFX4.exe
Additional information: Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.奇怪,但是,我试图引用(与Arduino.dll中相同的)Arduino.dll,但没有运气,我现在得到了一个更奇怪的错误:
An unhandled exception of type 'System.BadImageFormatException' occurred in LuxAFX4.exe
Additional information: Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)在我寻找解决方案的过程中,我明白我不应该尝试加载这个“参考库”,如果找不到它,肯定是因为它没有安装在系统上。但是,为什么它会在我的测试项目中工作呢?
我可能理解的另一件事是,如果我的库不公开引用的“子”库的成员,那么在引用我的库时就不需要它们了。我应该试着“隐藏”所有的推荐信吗?如果是的话,有没有办法抓住所有暴露的成员?来源:如何避免引用dll的引用dll
附带注意:我使用C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll和C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd。
发布于 2017-01-15 10:18:45
经过进一步的研究,在汉斯·帕桑特的暗示下,我终于明白,我当初选择了错误的System.Runtime.WindowsRuntime.dll。将其更改为在具有DLL的项目和使用C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll的项目中使用C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll,解决了我的问题。
我在这里找到了新的文件位置:使用桌面应用程序的C#“等待”错误
https://stackoverflow.com/questions/41649597
复制相似问题