Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# .Net 6.0 System.IO.Ports is depricated. How can I use SerialPort?

Tags:

c#

.net-6.0

I am C# programmer and using VS 2022, with .NET Framework is no problem using System.IO.Ports.SerialPort in order to use .GetPortNames() for collect available serial port list.

for example;

ComboBox CMS = new ComboBox();
string[] comlist = System.IO.SerialPort.GetPortNames();
CMS.Items.Clear();
//ComboBox item add if serial port is exist
if (comlist.Length > 0) CMS.Items.AddRange(comlist);

However, this code is not working on .NET 6.0. System.IO is exist but .Ports does not. So Ports.SerialPort... all removed.

How can I get Serial Ports list with .NET 6.0? I've searched and google a lot but can't find solution.

like image 877
Stephen W. Park Avatar asked Oct 20 '25 14:10

Stephen W. Park


1 Answers

Try adding the System.IO.Ports NuGet package:

<PackageReference Include="System.IO.Ports" Version="7.0.0" />

Also note that the fully qualified name is System.IO.Ports.SerialPort, not System.IO.SerialPort

like image 86
Marc Gravell Avatar answered Oct 22 '25 03:10

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!