Kamran Bigdely
Kamran Bigdely

Reputation: 8466

The type or namespace name 'Ports' does not exist in the namespace 'System.IO' (are you missing an assembly reference?)

In older versions of Unity (e.g. v5), I used to solve this issue by setting

Edit > Project Settings > Player > PC setting (icon) > Other Settings > API Compatibility Level

from .Net 2.0 Subset to .Net 2.0

but in Unity 2018.3.2f1, this doesn't solve the issue. I also set the same setting to .Net 4.x but it didn't help.

Note 1: My build settings is set to Android platform but I need SerialPort class from System.IO.Ports namespace in order to read the serial port while running the game in the Unity Editor (PC). I have done this before with Unity 5.

Note 2: I cannot manually add a reference to the related assembly in the Visual Studio project made by Unity. The command is removed.

Upvotes: 1

Views: 8858

Answers (2)

Samra Khan
Samra Khan

Reputation: 72

Go to Edit->projectsettings->Player->APIcompetibilityLevel = .Net4.x This worked for me.

check out this -> The type or namespace name 'Ports' does not exist in the namespace 'System.IO'

Upvotes: 1

Kamran Bigdely
Kamran Bigdely

Reputation: 8466

I came up with a workaround:

  1. Switch the platform to PC: File > Build Settings > (select) PC > 'Switch Platform' button.
  2. Go to Visual Studio and Build > Build Solution.
  3. Switch back to Android: File > Build Settings > (select) Android >'Switch Platform' button.

By doing that, Unity adds the required assembly to 'Assembly-CSharp-Editor' project (which is related to running game inside Unity Editor).

Upvotes: 0

Related Questions