System.IO.Ports missing for Unity with .NET 4.x

I very recently downloaded the stable release for Unity (2018.3.5f1). I have a project that talks to a microcontroller over the serial port, and in the past have used System.IO.Ports with no issue. However, just trying to import the namespace System.IO.Ports gives me this error in the editor and I am unable to compile:


error CS0234: The type or namespace name ‘Ports’ does not exist in the namespace ‘System.IO’ (are you missing an assembly reference?)


As you can see below, my configuration settings are to use .NET 4.x and compatibility level is set to 2.0 (NOT subset, which isn’t even available in the list):


133458-unity-settings.png


If I set the “Scripting Runtime Version” to “.NET 3.5 Equivalent”, the problem goes away. The only problem is that 3.5 is deprecated, and I would like to use something a little more future proof. Am I doing something wrong here? Do I need to check my .NET 4.x installation to see if it is missing some libraries? According to MSDN documentation, System.IO.Ports should be available in .NET 4.x. This problem persists across multiple machines & Unity installations of 2018.3.x. Any help greatly appreciated!!

Hello, you need to set api compatibility level to net 4.x(tested with 2018.3.0f2 version) 133459-sin-titulo.png

I had the same problem, and I can confirm that you first need to switch to the deprecated .NET 3.5 Equivalent first, before switching to .NET 4.X and setting the API compatibility level. Switching the API Compatibility level first, weirdly, doesn’t work.

I also had the same problem. I used scripting runtime version .net 4.x Equivalent and Api Compatibility Level .Net 4.x. But I needed to build the solution in the IDE after switching from .Net Standard 2.0 to .Net 4.x