Question No serial port in Toolbox

engr.ahayee

Member
Joined
Aug 10, 2021
Messages
16
Programming Experience
Beginner
Hi guys.
I have a question. I want to use serial port but in the toolbox serial port is not showing. can you tell me how to add serial port in it?
noserialport.png


Thanks
 
I'm not sure but I suspect that it's not included in the Toolbox because the class is declared in an assembly that is not included in the referenced frameworks. If you add the System.IO.Ports NuGet package to your project then you will be able to access the SerialPort class, so you can just declare a field in code and create the object yourself.
 
If you're using a current version of VS 2019 then you can create a project that targets .NET Framework or .NET Core. .NET 5 is based on .NET Core. All the .NET Framework project templates specify it in the name. It's possible that the tutorial you're following was created before .NET 5 was the default and so the WinForms Application project template without ".NET Framework" in the name actually did target .NET Framework.

You need to be aware of what you're targeting when you create a new project. There are various advantages to targeting .NET 5 but there are disadvantages too. While you're just learning, I would suggest that you stick to .NET Framework unless you have a specific reason to do otherwise. Microsoft will be supporting .NET Framework 4.8 for some time to come.
 
SOLUTION IN THIS VIDIO
THANKS

Note that that is a solution if creating a .NET Framework app is appropriate but if you actually want a .NET Core app then it's not. In that case, the SerialPort component cannot be added to the Toolbox, so the solution is to create one in code, which is very simple to do anyway.
 
Think they might have solved it by now

That post might help someone else but it really just amounts to what I said a year and a half ago: it's there for .NET Framework projects but not .NET (Core) projects. Creating a new project targeting .NET Framework isn't really a solution if you want to target .NET (Core). That said, I believe that there is currently no end date for support of .NET Framework 4.7 and later, so that's not an issue.
 
That post might help someone else but it really just amounts to what I said a year and a half ago: it's there for .NET Framework projects but not .NET (Core) projects. Creating a new project targeting .NET Framework isn't really a solution if you want to target .NET (Core). That said, I believe that there is currently no end date for support of .NET Framework 4.7 and later, so that's not an issue.

I'm actually following the same tutorial and having the same issue...
however I checked and my selected framework (at creation of the project) was .NET 8.0
I'm confused if the serial is not supported only in core or also starting from .NET 4.8

In my specifica case, can I add the directive using System.IO.Ports; ?
I mean I tried but then when i create the object e.g. SerialPort myPort = new SerialPort(); I have the error that report that SerialPort couldn't be found in namespace, since I'm completely new to all this, am I doing something wrong, missing something or where is my mistake?
thanks!
 
I'm actually following the same tutorial and having the same issue...
however I checked and my selected framework (at creation of the project) was .NET 8.0
I'm confused if the serial is not supported only in core or also starting from .NET 4.8

In my specifica case, can I add the directive using System.IO.Ports; ?
I mean I tried but then when i create the object e.g. SerialPort myPort = new SerialPort(); I have the error that report that SerialPort couldn't be found in namespace, since I'm completely new to all this, am I doing something wrong, missing something or where is my mistake?
thanks!

ALWAYS read the documentation. Here's the API reference home page:


Bookmark/favourite it in your browser. You can get there from the VS Help menu but it takes a few clicks. That's the Australian version but you can select whatever culture is appropriate.

If you search for the SerialPort class, you'll see that it is available for .NET 8, but you'll also see that it's not a standard part of it because it's Windows-specific. You have to add the appropriate NuGet package. That's why it's not in the Toolbox, presumably.
 
I'm actually following the same tutorial and having the same issue...
however I checked and my selected framework (at creation of the project) was .NET 8.0
I'm confused if the serial is not supported only in core or also starting from .NET 4.8

In my specifica case, can I add the directive using System.IO.Ports; ?
I mean I tried but then when i create the object e.g. SerialPort myPort = new SerialPort(); I have the error that report that SerialPort couldn't be found in namespace, since I'm completely new to all this, am I doing something wrong, missing something or where is my mistake?
thanks!

.NET 8 is not a "3.2 versions more advanced" successor to .NET Framework 4.8

First there was "widnows only" framework up to 4.6, then "linux too" .net core 1.0 became a thing. The two proceeded in parallel, with a focus on core, which rapidly advanced through the versions and dropped the "core" word around .net 5, as .net framework was heading into 4.8 - there is no direct correlation and .NET 5 and newer is not a direct successor to .NET Framework 4.8, but more like a sibling at grew independently and faster than its brother. Framework 4.8 will probably be the end of the line for that family, while .NET (core) derivatives will continue to advance
 
Back
Top Bottom