Share via


Cannot find system.io.ports in Visual Studio 2017

Question

Thursday, August 31, 2017 4:22 PM

I need to write an app that communicates with a radio (e.g. ICOM IC-7300) using a serial port using Visual Studio 2017.  I can find system.io but there is no longer a Ports Class in system.io.

Where do I find a SerialPort Class in Visual Studio 2017?

All replies (8)

Friday, September 1, 2017 6:43 AM ✅Answered

Hi K4RHB,

The system.io.ports assembly is added for .NET Framework by default, so you should start with the project which is based on .NET Framework, such as, Class library (.NET Framework), Console App (.NET Framework) instead of UWP (VB).

You will notice that the system.dll in the Universal Window project is comes from NuGet package Microsoft.NETCore.Portable.Compatibility rather than .NET framework:

So if you want to use system.io.ports, you should use it in the project which based on .NET Framework. I test that code sample in the Class library(.NET Framework), it works fine:

MSDN Community Support Please remember to click Mark as Answer; the responses that resolved your issue, and to click Unmark as Answer; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].


Thursday, August 31, 2017 4:34 PM

System.Io.Ports namespace is part of the Framework since.... all the time or 2.0, so you should have access to it.

It is referenced in the system.dll assembly. Does you project has system.dll in its references?


Thursday, August 31, 2017 6:44 PM

I am brand new to Visual Studio 2017.  I have been unable to find system.dll to reference it.  I am not sure if I'm using Add Reference correctly to find system.dll.

I believe the Add Reference Dialog has changed significantly in Visual Studio 2017 from prior versions.  Can you give me instructions on how to use the Add Reference Dialog to find and reference system.dll?


Thursday, August 31, 2017 7:00 PM

I am brand new to Visual Studio 2017.  I have been unable to find system.dll to reference it.  I am not sure if I'm using Add Reference correctly to find system.dll.

I believe the Add Reference Dialog has changed significantly in Visual Studio 2017 from prior versions.  Can you give me instructions on how to use the Add Reference Dialog to find and reference system.dll?

The System assembly is added for you by default.

Are you using C#?

Can you please paste some of your code here? Specifically the snippet where you want to use SerialPort class.

My Technet Articles

If you like this or another reply, vote it up!
If you think this or another reply answers the original question, mark it or propose it as an answer.

Mauricio Feijo
www.mauriciofeijo.com


Thursday, August 31, 2017 7:10 PM

I don't know C# but I used Visual Basic for several projects years ago.  I am in the process of learning Visual Basic as it exists in Visual Studio.

I copied the code below from an article written by John B in stackoverflow.  I can't get it to compile in Visual Studio 2017 because there is no system.io.Ports.

mports System.Threading

Imports System.IO

Imports System.Text

Imports System.IO.Ports


Public Class clsBarcodeScanner

Public Event ScanDataRecieved(ByVal data As String)
WithEvents comPort As SerialPort

Public Sub Connect()
    Try
        comPort = My.Computer.Ports.OpenSerialPort("COM5", 9600)
    Catch
    End Try
End Sub

Public Sub Disconnect()

    If comPort IsNot Nothing AndAlso comPort.IsOpen Then
        comPort.Close()
    End If

End Sub

Private Sub comPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles comPort.DataReceived
    Dim str As String = ""
    If e.EventType = SerialData.Chars Then
        Do
            Dim bytecount As Integer = comPort.BytesToRead

            If bytecount = 0 Then
                Exit Do
            End If
            Dim byteBuffer(bytecount) As Byte


            comPort.Read(byteBuffer, 0, bytecount)
            str = str & System.Text.Encoding.ASCII.GetString(byteBuffer, 0, 1)

        Loop
    End If

    RaiseEvent ScanDataRecieved(str)

End Sub
End Class

Thursday, August 31, 2017 7:19 PM

I don't know C# but I used Visual Basic for several projects years ago.  I am in the process of learning Visual Basic as it exists in Visual Studio.

I copied the code below from an article written by John B in stackoverflow.  I can't get it to compile in Visual Studio 2017 because there is no system.io.Ports.

To verify the class and the namespace exist in an assembly, Click on the View Menu, Select Object Browser. Expand System. You will see the namespaces under SYstem. System.IO and System.IO.Ports should be there.

Are they not?

If not, what is the project type you picked when you started this VS project?

My Technet Articles

If you like this or another reply, vote it up!
If you think this or another reply answers the original question, mark it or propose it as an answer.

Mauricio Feijo
www.mauriciofeijo.com


Thursday, August 31, 2017 7:52 PM

Hi Mario,

I started with a Universal Window project.

I used the Object Browser as you suggested.  There are four different "system" objects listed:

system [2.0.0.0]

system [2.0.5.0]

system [2.4]

system [4.0.0.0]

I found the Ports Class in system [2.0.0.0].  The following information is given for the system [2.0.0.0] object.  Is there some way I can use this information in Visual Studio 2017 to gain access to system.io.ports?

Assembly System
    Member of .NET Framework 2.0, .NET Framework 3.0, .NET Framework 3.5, Custom Component Set
    C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll

Attributes:
<System.Reflection.AssemblyProductAttribute("Microsoft® .NET Framework"),
System.Reflection.AssemblyDefaultAliasAttribute("System.dll"),
System.Reflection.AssemblyInformationalVersionAttribute("2.0.50727.8793"),
System.Reflection.AssemblyCompanyAttribute("Microsoft Corporation"),
System.Reflection.AssemblyDescriptionAttribute("System.dll"),
System.Reflection.AssemblyTitleAttribute("System.dll"),
System.Security.AllowPartiallyTrustedCallersAttribute,
System.CLSCompliantAttribute(True),
System.Runtime.InteropServices.ComVisibleAttribute(False),
System.Diagnostics.DebuggableAttribute(2),
System.Runtime.CompilerServices.CompilationRelaxationsAttribute(8),
System.Reflection.AssemblyFileVersionAttribute("2.0.50727.8793"),
System.Reflection.AssemblyCopyrightAttribute("© Microsoft Corporation.  All rights reserved."),
System.Runtime.CompilerServices.DefaultDependencyAttribute(1),
System.Runtime.CompilerServices.StringFreezingAttribute,
System.Runtime.CompilerServices.RuntimeCompatibilityAttribute(WrapNonExceptionThrows = True),
System.Runtime.InteropServices.ComCompatibleVersionAttribute(1, 0, 3300, 0),
System.Reflection.AssemblyKeyFileAttribute("f:\dd\Tools\devdiv\EcmaPublicKey.snk"),
System.Reflection.AssemblyDelaySignAttribute(True),
System.Resources.NeutralResourcesLanguageAttribute("en-US"),
System.Resources.SatelliteContractVersionAttribute("2.0.0.0")>


Friday, September 1, 2017 4:39 PM

Hi Leo--Liu,

Thank you so much for an answer that works!  How do I give you points on this forum?