Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileNotFoundException: Could not load file or assembly System.IO.Ports

Yesterday I've worked on a project and got this exception:

System.IO.FileNotFoundException: Could not load file or assembly. The system cannot find the file specified.

Then I've Googled for hours what the problem could be but didn't find a solution.

The weird thing is that I've started with a complete new .NET Core project today and I've installed the Lego.Ev3 NuGet library and got the same error again.

This is my code, the exception will thrown on the last line:

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

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

This are more details of the exception in my Lego© project:

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.**

Is there a setting wrong in Visual Studio?

like image 379
H. Pauwelyn Avatar asked Mar 03 '23 23:03

H. Pauwelyn


2 Answers

System.IO.Ports is not available in .NET Core. It's only available in .NET Framework 4.8.

https://learn.microsoft.com/en-us/dotnet/api/system.io.ports

As a possible solution, try to create a project with .NET Framework 4.8, not with .NET Core.

like image 84
SQL Police Avatar answered Mar 05 '23 18:03

SQL Police


Sorry for answering an old question, but I got around this by adding System.IO.Ports nuget package.

I wasn't working with the Lego library, so I don't know if it's a fix for that specifically, but it worked for the library I am using.

like image 37
Ken Avatar answered Mar 05 '23 18:03

Ken