ArcGIS Pro 3.1 SDK加载System.Text.Json 7.0.0.0程序集失败求助
问题场景
将ArcGIS Pro插件从2.8版本升级至3.1版本后,使用Microsoft.Extensions.Configuration.Json读取配置文件的代码抛出异常。执行代码如下:
IConfigurationRoot config = new ConfigurationBuilder() .AddJsonFile(@"C:\Users\XXX\Data\config.json", false, true) .Build();
抛出的错误信息:
System.IO.InvalidDataException: 'Failed to load configuration from file 'C:\Users\XXX\Data\config.json'.'
FileNotFoundException: Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
已确认System.Text.Json 7.0.0包已安装,对应dll存在于项目bin文件夹和AddIn AssemblyCache文件夹中,且尝试过以下方法均无效:
- 清理解决方案并重新生成
- 重启Visual Studio及电脑
- 确认已安装.NET 6.0运行时及桌面运行时
- 直接安装该包并在.csproj文件中添加PackageReference
- 将生成类型设置为Any CPU
- 以Release模式生成
- 更新/降级该包
- 移除所有NuGet包后重新安装
新增解决思路
- 添加程序集绑定重定向
在插件的配置文件(如YourAddIn.dll.config)中添加绑定重定向规则,引导运行时找到正确版本的System.Text.Json:
<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
确保该配置文件随插件一同部署到ArcGIS Pro的加载目录。
适配ArcGIS Pro的.NET版本降级包
ArcGIS Pro 3.1基于.NET 6运行环境,高版本NuGet包可能存在兼容性问题。尝试将System.Text.Json降级至6.0.x版本,使用.NET 6官方配套版本,减少版本不匹配导致的加载异常。手动部署dll到ArcGIS Pro运行目录
将System.Text.Json.dll(7.0.0版本)手动复制到ArcGIS Pro安装目录的bin文件夹(通常路径为C:\Program Files\ArcGIS\Pro\bin),强制让ArcGIS Pro加载该dll文件。修改项目私有部署配置
在.csproj文件中明确设置System.Text.Json的私有部署属性,确保dll被正确复制到输出目录并被插件加载:
<PackageReference Include="System.Text.Json" Version="7.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference>
同时确认开启本地复制锁定文件程序集:
<PropertyGroup> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> </PropertyGroup>
- 调整配置文件读取路径
ArcGIS Pro插件有独立的加载上下文,可能无法直接读取外部路径的dll。将config.json复制到插件输出目录(bin/Release或bin/Debug),修改代码使用相对路径读取:
var configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"); IConfigurationRoot config = new ConfigurationBuilder() .AddJsonFile(configPath, false, true) .Build();
- 用程序集绑定日志诊断加载过程
启用程序集绑定日志查看器(fuslogvw.exe),定位System.Text.Json加载失败的具体原因:
- 以管理员身份运行
fuslogvw.exe - 点击「设置」,选择「记录所有程序集绑定失败」
- 运行插件触发错误,回到工具查看详细加载日志,排查路径或版本冲突问题
内容的提问来源于stack exchange,提问作者Pau

