The type or namespace name 'Ports' does not exist in the namespace 'System.IO'

心已入冬 提交于 2020-07-19 05:29:49

问题


I am working on developing a windows store app on my windows 8.1 system,64 bit (I need to deploy this app on my windows surface pro 3 tablet), technology being used is C#. I need to communicate through the RS-232 port. For this I am using the SerialPort class which falls under the namespace System.IO.Ports. But when I am including this in my C# code, I am getting the error -

"The type or namespace name 'Ports' does not exist in the namespace 'System.IO' (are you missing an assembly reference?)"

I have the windows SDK 8.0 installed. What could be the probable reason for this issue ? Is there any other was to communicate through the RS-232 port .

I am working on developing a windows store app on my windows 8.1 system,64 bit (I need to deploy this app on my windows surface pro 3 tablet), technology being used is C#. I need to communicate through the RS-232 port. For this I am using the SerialPort class which falls under the namespace System.IO.Ports. But when I am including this in my C# code, I am getting the error -

"The type or namespace name 'Ports' does not exist in the namespace 'System.IO' (are you missing an assembly reference?)"

I have the windows SDK 8.0 installed. What could be the probable reason for this issue ? Is there any other was to communicate through the RS-232 port .

Any pointer or suggested would be really helpful.

Here is the code -

using System;
using System.IO;
using System.IO.Ports;

namespace App4
{
    public class Class2
    {
        private SerialPort comport = new SerialPort();
    }

    private void SerialPortInit()
        {

            comport.BaudRate = 115200;
            comport.DataBits = 8;
            comport.StopBits = StopBits.One;
            comport.Parity = Parity.None;

        }
}

Google says that Serialport class is supported in dotNetFrameWork 4.5 (which is the one I am using) but still I am getting this error.

Regards, Shikha


回答1:


Problem is the .net configuration.

Use the .NET 2.0 (not subset). Config:

Edit>ProjectSettings>Player>ApiCompatibilityLevel




回答2:


*This answer is valid for VC++ but I think it is same or similar for C#.

Open Project Properties -> C/C++ -> Command Line. There is an "Additional Options" box below. Add following lines to there:

/FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Drawing.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Windows.Forms.dll" /FU"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Xml.dll" 

Pay attention to the path and .NET version before adding them.




回答3:


I hit the same issue with .Net Core 3.1

How to build cross-platform console apps with .NET Core

Add following to .csproj:

<PropertyGroup>
<RuntimeIdentifiers>win10-x64;osx.10.12-x64;debian.8-x64</RuntimeIdentifiers>

Then installed the package System.IO.Ports 4.7.0




回答4:


Go to Edit->projectsettings->Player->APIcompetibilityLevel = .Net4.x This worked for me.



来源:https://stackoverflow.com/questions/26863021/the-type-or-namespace-name-ports-does-not-exist-in-the-namespace-system-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!