Pau
Pau

Reputation: 372

Could not load file or assembly 'System.Text.Json, Version=7.0.0.0' in ArcGIS Pro 3.1 SDK for .NET

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:

  1. Clean the solution and rebuild
  2. Restart Visual Studio and/or the computer
  3. Checked the .NET runtime and desktop runtimes are installed (from https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
  4. Installed the package directly (not as a dependency) and added a PackageReference Include="System.Text.Json" Version="7.0.0" /> to the project .csproj file
  5. Set the build type to 'Any CPU'
  6. Built as 'release'
  7. Updating/Downgrading the package
  8. Removing all the NuGet and reinstalling

So far nothing has worked. Does anyone have any other ideas? Many thanks for your help.

Upvotes: 1

Views: 2030

Answers (1)

Pau
Pau

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

Related Questions