System.IO.Ports gives an exception

Hi,

I am currently developing an instrument plugin that uses serial ports to communicate. Since the plugin project targets .net standard 2.0, i installed System.IO.Ports nuget package. I just want to connect to the device and send messages. However, when i create the device in the editor, it gives an error. Error message is as follows:

"System.PlatformNotSupportedException System.IO.Ports is currently only supported on Windows "

I created the package without an error, and in the package.xml file System.IO.Ports.dll dependency is added. I also added the dll file to the dependency folder in the OpenTAP installation directory. I wonder if i am doing something wrong, if any one can help i would appreciate it.

2 Likes

Hi @btyilmaz, and welcome to the forum!

I can reproduce your issue with a blank C# project. This issue is that the default .netstandard dll is a cross platform DLL, which just won’t work on any platform at all.

I managed to get ‘the right’ System.IO.Ports.dll by adding this inside a PropertyGroup in your csproj.

        <RuntimeIdentifier>win</RuntimeIdentifier>
2 Likes

Thank you very much. It didn’t work at first. I created a new project and created the package again, then added the RuntimeIdentifier and it worked as i wanted. I think i changed something that i should not in the first project that i created.

Best regards

3 Likes

I struggled with this as well. The best solution I found (using net462) is described in the CSPROJ file.

<!-- We are debugging using NET Framework, but builds to Netstandard in release mode to ensure cross platform compatibility -->
<!-- If your plugin is Windows only and you use Windows specific API's, feel free to change "netstandard2.0" below to "net462" and everything will work as when you are debugging. In this case, remember to change "OS" in package.xml to only "windows" -->
<!-- If your plugin should be cross platform but does not build in release mode, please verify that all API's you used are available. You might need references or nuget packages for API's that are available in NET framework, but not in NetStandard -->
3 Likes