I am developing a managed plug-in to interface with a hardware device and I need to use System.IO.Ports. The plug-in is developed outside Unity, as a Class Library (.Net Standard 2.0), compiled as a dll and placed in Assets/Plugins. The System.IO.Ports is installed as a Nuget package.
I am using Unity 2020.2.x
I am copying the System.IO.Ports dll from my VS solution into the Plugins folder in Unity, but when I run the code it fails with an exception:
System.PlatformNotSupportedException: System.IO.Ports is currently only supported on Windows. at System.IO.Ports.SerialPort.GetPortNames () [0x00005] in <5fbfe4b89abd41dd9fce05171c2bebc8>:0
The project is actually set up as Windows Standalone, so the error message is misleading.
If I don’t copy the dll across, the system won’t find the System.IO.Ports namespace and complain about missing assemblies.
System.IO.Ports is available in Unity if we set the project to .Net 4.x, but unfortunately, I cannot use .Net 4.x as I have some dependencies on APIs that are only present in .Net Standard 2.0.
Is it possible to use Nuget libraries in Unity at all? Is this only an issue with this particular package? Is there a workaround to get System.IO.Ports working with .Net Standard 2.0?