Reputation: 372
I have upgraded an ArcGIS Pro 3.1 Add-In from version 2.8. The Add-In uses Microsoft.Extensions.Configuration.Json
to manage a configuration file.
However, when the code tries to read the config file:
IConfigurationRoot config = new ConfigurationBuilder()
.AddJsonFile(@"C:\Users\XXX\Data\config.json", false, true)
.Build();
It throws the following error:
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.
The System.Text.Json
package is installed and the version is 7.0.0. The dll appears in the bin folder and the AddIn AssemblyCache folder. I have seen other questions about this error, but none of the answers helped (sadly). Here are some things I have tried:
PackageReference Include="System.Text.Json" Version="7.0.0" />
to the project .csproj
fileSo far nothing has worked. Does anyone have any other ideas? Many thanks for your help.
Upvotes: 1
Views: 2030
Reputation: 372
In the end the solution was to downgrade both Microsoft.Extensions.Configuration.Json
and System.Text.Json
to 6.0.0. Despite that the NuGet manager recommends using 7.0.0 for both of them when targeting .NET6, and that we are using Microsoft.Extensions.Configuration
at 7.0.0 as well.
Setting Microsoft.Extensions.Configuration
to 6.0.0 doesn't work either. Somehow this is the only setup that works.
Upvotes: 2