Referencing a .NET Standard 2.0 project with a .NET 4.7.2 project > System.IO.Ports not implemented

723 views Asked by At

Project A is a Windows Console Application that uses .NET Standard 2.0 (for compatibility) and has the following line of code

    public List<string> GetListOfSerialPorts()
    {
        return System.IO.Ports.SerialPort.GetPortNames().Distinct().ToList();
    }

Local unit tests run this code successfully. Meaning that when called from a local unit test, it works.

I now have a Project B (in the same Solution), which is a Windows GUI based on .NET 4.7.2. . This project does not need to as large compatibility. This project "uses" (references) Project A. The same function is called but from Project B and when that exact same line of code is called, I see an exception:

"System.IO.Ports is currently only supported on Windows.").

Help?? Any clues?

As a side note, if I try to implement 'SerialPort.GetPortNames()' in Project B, Visual Studio complains that it cannot reference the System.IO.Ports assembly but when I add it as a reference to the project, it complains that there are now two (ambiguous) references to System.IO.Ports (it is apparently already in 'System'). Note that this is not my main issue. My main issue is that my original line of code in Project A now fails when called from Project B.

Note that we have Microsoft.Windows.Compatibility 3.1.1 installed.

1

There are 1 answers

0
Ed Landau On

I resolved my issue by installing Microsoft Windows Compatibility dependency on Project B and it worked. I was under the impression it was only needed on the .NET Core project.