SerialPorts with .NET Standard 2.1

Hi,
Sorry if this is in the wrong place.

I’m trying to get serial ports working with .NET Standard 2.1. It works with .NET Framework but ideally, I don’t want to use this if I don’t have to.

I understand that .NET 2.0 was the last version to have serial support directly and now it’s available via the NuGet package NuGet Gallery | System.IO.Ports 8.0.0
However, I’m unable to get this to work.

Using the .NET Standard 2.0 gets me the following error:

Exception: System.IO.Ports is currently only supported on Windows. StackTrace:   at System.IO.Ports.SerialPort..ctor (System.String portName, System.Int32 baudRate) [0x0000b] in <c6d1344d4a914d5aba16ee2e4d4a5e71>:0
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort..ctor(string,int)

I’m wondering if it’s possible to use the mono implementation? I tried to include it using a csc.rsp but no luck.

Any help is greatly appreciated.

EDIT: I actually managed to get this to work in the end.
When opening the NuGet package I was using the netstandard2.0 dll’s from the lib directory but I noticed there is a runtime directory with the same netstandard2.0 directory and dll’s. I used this with my editor set to .NET Standard 2.1 and it works.
I hope this helps those in the future.

8 Likes

Hi, I received the same error message - only supported on windows even though I have NET standard 2.1. And seems my OVR camera rigs are missing too. Do you know any alternative in solving this issue?

Still looking for a solution for this.