FileNotFoundException: Couldn't load System.IO.Ports

I’m getting a System.IO.FileNotFoundException exception when running my .NET Core project with the Lego.Ev3 NuGet library. I’ve started a new project today and installed the library, but the same error persists. The exact details of the exception are:

System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.Ports, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

My code is:

using Lego.Ev3.Core;
using Lego.Ev3.Desktop;

Brick brick = new Brick(new BluetoothCommunication("COM10"));

I’m not sure what the problem is. Could it be an incorrect Visual Studio setting?

This error occurs because the System.IO.Ports assembly is missing. You can try adding it manually by right-clicking on your project in Visual Studio and selecting “Add Reference”. Then, search for System.IO.Ports and add it. If that doesn’t work, you can try updating the Lego.Ev3 NuGet package to the latest version or checking if there are any dependencies that need to be installed.