You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

同一解决方案中System.IO.Ports NuGet包运行时加载失败求助

问题:System.IO.Ports 8.0.0.0程序集运行时加载失败

同一解决方案下的两个项目均安装了System.IO.Ports 8.0.0版本的NuGet包,其中一个项目运行正常,另一个却在运行时抛出程序集找不到的错误。

错误信息

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.IO.Ports, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.'

项目配置对比

问题项目的csproj配置

<PropertyGroup>
  <TargetFramework>net8.0-windows</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
  <PackageReference Include="System.Drawing.Common" Version="8.0.8" />
  <PackageReference Include="System.IO.Ports" Version="8.0.0" />
  <PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
</ItemGroup>

正常项目的csproj配置

<PropertyGroup>
  <TargetFramework>net8.0-windows</TargetFramework>
  <OutputType>Library</OutputType>
  <SccProjectName></SccProjectName>
  <SccLocalPath></SccLocalPath>
  <SccAuxPath></SccAuxPath>
  <SccProvider></SccProvider>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  <UseWindowsForms>true</UseWindowsForms>
  <UseWPF>true</UseWPF>
  <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="Dapper" Version="2.1.35" />
  <PackageReference Include="DapperLinqProfilerCore" Version="3.0.0" />
  <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
  <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
  <PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.8" />
  <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
  <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
  <PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
  <PackageReference Include="System.IO.Ports" Version="8.0.0" />
  <PackageReference Include="Unity" Version="5.11.10" />
  <PackageReference Include="Unity.Container" Version="5.11.11" />
</ItemGroup>

已尝试的解决操作

  • 将System.IO.Ports的DLL手动复制到项目Debug输出文件夹
  • 删除项目bin目录后重新构建
  • 清理并重建整个解决方案
  • 清除NuGet缓存
  • 删除本地NuGet包目录(C:\Users\Maria.nuget\packages\system.io.ports)后重新安装该包

注:两个项目均通过串口与不同设备通信,此前正常项目可正常运行,但目前无法再次测试其状态,推测该问题可能由NuGet包管理器的bug导致。

内容的提问来源于stack exchange,提问作者Maria

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 15:09:53