Running Dot Net project exe on Linux which makes use of System.Management to get USB Device information

早过忘川 提交于 2019-12-11 04:23:56

问题


Hi, I have created a Dot Net application in C# to get USB Device Information like DeviceID, Caption, ClassGUID etc using System.Management Namespace. I'm using the ManagementObjectSearcher Method to fetch the value from Win32_DiskDrive. It's running fine on Windows. I want to run it on Linux machine. You can run Dot Net applications on Linux machine using Mono.

http://mono-project.com/Main_Page

When i run my application's exe on Linux using Mono i get the following error:

    Missing method .ctor in assembly /home/dvimay11/USBCamInfoNew/Debug/System.Management.dll, type System.Reflection.AssemblySignatureKeyAttribute
Can't find custom attr constructor image: /home/dvimay11/USBCamInfoNew/Debug/System.Management.dll mtoken: 0x0a000009

Unhandled Exception: System.TypeLoadException: Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'System.Management'.
  at USBCamInfo.USBInfo.GetUSBDevices () [0x00000] in <filename unknown>:0 
  at USBCamInfo.USBInfo.LoadUSBInfo () [0x00000] in <filename unknown>:0 
  at USBCamInfo.USBInfo..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) USBCamInfo.USBInfo:.ctor ()
  at USBCamInfo.Program.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'System.Management'.
  at USBCamInfo.USBInfo.GetUSBDevices () [0x00000] in <filename unknown>:0 
  at USBCamInfo.USBInfo.LoadUSBInfo () [0x00000] in <filename unknown>:0 
  at USBCamInfo.USBInfo..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) USBCamInfo.USBInfo:.ctor ()
  at USBCamInfo.Program.Main () [0x00000] in <filename unknown>:0

Can anyone help me to fix this issue. I wanted to know how i can run my Dot Net exe on a Linux machine using the System.Management Namespace to retrieve information of USB Device

Thanks


回答1:


If you look at the Mono Project Roadmap you'll find that System.Management is Windows specific and there are no plans to support it.

You could use SharpUsbLib instead which has support for USB under Linux.



来源:https://stackoverflow.com/questions/15973610/running-dot-net-project-exe-on-linux-which-makes-use-of-system-management-to-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!