Why Unity does not accept System.IO.Ports namespace?


I'm not sure about this, but you might be able to change the Mono subset to one which contains more classes, perhaps System.IO.Ports.

I think the setting is in the Project Settings-->Player Settings, down at the bottom. Per default it is .Net Subset.

Because Unity did not include it in their subset of mono that they selected to include.

System.IO.Ports is used to access serial ports. As this is only meaningful for standalone desktop builds and would likely lead to difficulty and complications as Unity simply was not designed to provide direct hardware interfacing, it was likely deemed unnecessary. If you want this functionality, you will have to access it through a plug-in (Pro only) or some external Process that you start which does the work for you outside of Unity.

Go to player settings ,other settings ,configuration,change api compatibility level to .NET 4.x
Works in 2018.3.
Hope it helps