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

.NET 8迁移时ClosedXML遇System.Memory报错,求解决方案

解决ClosedXML在.NET 8中调用XLWorkbook时的FileNotFoundException问题

排查与修复步骤

  • 清理缓存并重新还原依赖
    删除项目目录下的bin、obj文件夹,然后在终端执行:

    dotnet restore
    

    强制重新拉取所有NuGet包,避免缓存的旧版本依赖引发冲突。

  • 确认ClosedXML版本兼容性
    确保安装的ClosedXML是支持.NET 8的最新稳定版本(当前推荐0.102.0及以上),可通过NuGet包管理器更新,或执行命令:

    dotnet add package ClosedXML --version 0.102.1
    
  • 定位缺失的具体依赖
    打开Visual Studio的输出窗口(切换到"调试"输出模式),运行项目时查看FileNotFoundException的详细信息,确认具体缺失的dll文件。这类问题常因ClosedXML依赖的其他库(如DocumentFormat.OpenXml)未正确安装或版本不匹配导致。
    若提示找不到DocumentFormat.OpenXml.dll,直接安装对应版本:

    dotnet add package DocumentFormat.OpenXml --version 3.0.2
    
  • 固定依赖版本避免冲突
    在项目的.csproj文件中明确指定所有相关依赖的版本,强制统一加载:

    <ItemGroup>
      <PackageReference Include="ClosedXML" Version="0.102.1" />
      <PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
      <PackageReference Include="System.Memory" Version="4.5.5" />
    </ItemGroup>
    
  • 检查目标框架配置
    确认项目.csproj中的目标框架设置正确,避免多框架配置导致依赖加载混乱:

    <TargetFramework>net8.0</TargetFramework>
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 18:53:11