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

3

6

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?

Shaftesbury answered 4/1, 2020 at 13:0 Comment(2)
Have you checked whether the specified path and file actually exists?Tremulous
Does Lego.Ev3 have Standard/Core support? Maybe it is running framework, and have library dependencies?Guinness
B
7

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.

Blither answered 4/1, 2020 at 13:4 Comment(1)
Thanks, that was my issue - a Core app trying to reference an old DLL that referenced IO.Ports...Allopath
P
4

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.

Plosion answered 19/7, 2021 at 23:54 Comment(2)
This worked for me, simply including this nuget library: nuget.org/packages/System.IO.PortsMammiemammiferous
Works for me too.Jecoa
M
1

I got this error when trying to communicate using SerialPort with a LTE Module on a RaspberryPi using c#/.net core. I had the nuget package "System.IO.Ports" installed, but when I scp:ed the files to the RaspberryPi, I missed to include the folder "runtimes" in the publish folder, it contains the native code that is needed for it to work.

Mcclanahan answered 26/4, 2023 at 13:16 Comment(1)
I have the same problem. Can you add more details of the solution? Where can I get the "runtimes" folder? Is it from the top level folder (path is ../ from publish folder)? In my project this folder contains many folders such as "linux-arm", "linux-arm64" and others. The "linux-arm" folder contains a "native" folder with .so libraries. I placed all the files from "linux-arm" into the publish folder. But it didn't work.Longlimbed

© 2022 - 2024 — McMap. All rights reserved.