【问题标题】:Namespace "System::IO" has no member "ports"命名空间“System::IO”没有成员“ports”
【发布时间】:2021-04-23 16:16:41
【问题描述】:

我正在使用 Visual Studio 2019。我正在修改我找到的旧代码,但它有这个错误:

命名空间“System::IO”没有成员“Ports”

目标是创建一个插件,扩展名为 .dll,我已经有一个 C++/CLI 文件。代码:

#include "DisplaySteering.hpp"          
#include <math.h>               
#include <stdio.h>              
#include <stdlib.h>
#using <system.dll> 
#include <string.h>
#include <tlhelp32.h>
#include <comdef.h>
#include <time.h>

using namespace System;
using namespace System::IO;
using namespace System::IO::Ports;
using namespace System::Runtime::InteropServices;

我知道我必须激活课程,但是如何激活?我看到了这个帖子namespace system has no member Drawing in c++ 但找不到端口选项(链接是 Visual Studio 2017,我有 2019)

这可能是一个非常初学者的问题,但找不到有效的答案。提前谢谢!

【问题讨论】:

    标签: c++ port visual-studio-2019 system


    【解决方案1】:

    每当您看到 .net 编译器抱怨它不知道的东西,但您确定它存在时,请查看文档以检查它是在哪个程序集中实现的。

    不幸的是,这仅适用于类(因为命名空间可以分布在多个程序集中),因此请选择您要使用的类并打开其文档,例如:

    https://docs.microsoft.com/dotnet/api/system.io.ports.serialport

    确保在左侧的下拉列表中选择您正在使用的 .net 版本。

    然后,在顶部,它告诉您对于 .net Framework 5,该类是在 System.IO.Ports.dll 中实现的,这可能是您在编译程序时需要引用的程序集。

    【讨论】:

    • 感谢您的宝贵时间。在询问之前我已经阅读了此文档,但我不知道我是否正确调用它,因为我已经尝试过include &lt;System.IO.Ports.dll&gt; 并给出了错误origin file couldn't be opened。我也试过using System.IO.Ports;,但是这个给出了错误namespace "System::IO" has no member "Ports"。我错过了什么?
    • 对不起,我的意思是#include &lt;System.IO.Ports.dll&gt;
    • 出于好奇,我自己尝试过,我认为您应该通过 nuget 添加对 System.IO.Ports.dll 的引用。但是,nuget 似乎不适用于 C++/CLI 项目。我通过创建一个 C# 项目解决了这个问题,在那里添加了 nuget 引用,选择了 DLL 并添加了对 C++/CLI 项目的引用......然后它编译了。
    • 这对我的水平来说看起来真的很复杂......请我私下和你谈谈吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 2021-06-05
    相关资源
    最近更新 更多