0

I am trying to use a DLL file along with Visual Studio in C# but upon running the code snippet it returns the error message in the title. I have tried updating powershell, downloading Microsoft SDKs, and updating Visual Studio all of which allegedly should have fixed the problems according to other posts but none of them have helped fix the issue. Could the issue be with the DLL file or is there a way for me to further figure out the issue causing the error? Any help is appreciated. Thank you.code snippet

I have followed the directions in the supplied pdf insctructing me to download the necessary drivers for the camera I'm using which are confirmed to be working and am using the correct DLL file supplied by the company. When running the code snippet it should return a list of COM ports available on my laptop but instead returns the error "System.IO.FileNotFoundException: Could not load file or assembly 'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. File name: 'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at NixLibrary.SerialPortTools.SerialPortPopulate() at Program.$(String[] args) in C:\Users\thebe\source\repos\NixAutomation\NixAutomation\Program.cs:line 15"

  • It is a typical .NET5+ error. .NETCore has *some* backwards compatibility but not for System.Management. Migrate the project that has this reference, use the [nuget package](https://www.nuget.org/packages/System.Management/6.0.0) – Hans Passant Mar 22 '23 at 21:47
  • Thank you for that. That issue has been resolved looks like but now I'm getting "System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.Ports, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. File name: 'System.IO.Ports, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' at NixLibrary.SerialPortTools.SerialPortPopulate() at Program.
    $(String[] args) in C:\Users\thebe\source\repos\NixAutomation\NixAutomation\Program.cs:line 15" Is this issue the same or is there a known fix?
    – Ikaika Lee Mar 22 '23 at 21:53
  • Maybe you'd better pick the correct project template to get started with this library. Which is probably "Console App (.NET Framework)". Contact the library's owner for support if that doesn't help. – Hans Passant Mar 22 '23 at 21:59
  • I remade the project using the "Console App (.NET Framework)" template and am getting the same issue. I will email them, thank you for your help it is much appreciated. – Ikaika Lee Mar 22 '23 at 22:04
  • I suggest turning on [assembly binding failure logs](https://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net) to get more information – John Wu Mar 22 '23 at 22:57

2 Answers2

0

Use the System.IO.Ports namespace.

 string[] AvailablePorts = SerialPort.GetPortNames();
reakt
  • 500
  • 8
  • 25
  • That line is given by the library of the camera I'm trying to use along with the DLL file so I don't believe it can be changed like that. I tried regardless but it flagged it with errors saying that SerialPort was unrecognized. – Ikaika Lee Mar 22 '23 at 21:58
0

"'It is a typical .NET5+ error. .NETCore has some backwards compatibility but not for System.Management. Migrate the project that has this reference, use the nuget package' – Hans Passant"