首页 > 解决方案 > 在 .NETCore 3.1 和 4.7 System.IO.Ports 中获取“PlatformNotSupportedException”

问题描述

我正在开发使用 System.IO.Ports 的多平台库。

库是用 .NET Core 3.1 编写的,并使用来自 Nuget 的 System.IO.Ports 4.7,显然这个版本应该已经可以在 linux 上使用,但支持 linux。但是当我运行主应用程序时,它仍然会导致同样的问题

System.PlatformNotSupportedException: System.IO.Ports is currently only supported on Windows.
   at System.IO.Ports.SerialPort..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits)

当我在谷歌上搜索这个问题时,我发现 System.IO.Ports 4.7 和 .NET Core 3.1 的组合应该可以在 linux 上运行,但没有。

PS我也尝试了不同的库crozone.SerialPorts,但是每个库都有一些不工作的问题,feinvlaid parameter when running /dev/stty等......是否有一些库可以解决这个问题,linux/windows使用串行端口?

非常感谢

标签: c#linux.net-coreserial-port

解决方案


您必须安装 System.IO.Ports 包(不是仅 dll 文件),其中包括:

-Microsoft.win32.Registry ...

-系统.内存

-runtime.native.System.IO.ports ...

-System.ioPorts.dll

如果您要使用的软件包版本高于 VS nuget 中存在的版本,您可以使用软件包管理器控制台安装它。

这种方法对我有用


推荐阅读