'*System.Text.Json* unable to load when VisualStudio is not installed

I have a DLL based on netcoreapp3.1. The DLL references the NuGet package Microsoft.Extensions.Configuration.Json version 5.0.0. If I deploy the DLL to another PC where VisualStudio is not installed and try to access it from a third party program, I get the error:

Could not load file or assembly 'System.Text.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)

If I install VS on that PC, it works. If I uninstall VS the error appears again.

Apparently VS add some components that are needed for my DLL. How can I resolve that?

Steps I Tried To Resolve

  • I explicitly added the NuGet Package System.Text.Json Version 5.0.2. Error still appears.

The .csproj file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
    <Version>1.0.3</Version>
    <AssemblyVersion>1.0.2.0</AssemblyVersion>
    <FileVersion>1.0.3.0</FileVersion>
    <Copyright>ZOOM Informatik GmbH, Grenchen, Schweiz</Copyright>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="publish\**" />
    <EmbeddedResource Remove="publish\**" />
    <None Remove="publish\**" />
  </ItemGroup>

  <ItemGroup>
    <None Remove="SapServiceReference\swagger.json" />
  </ItemGroup>

  <ItemGroup>
    <OpenApiReference Include="SapServiceReference\swagger.json" ClassName="SapServiceReference" CodeGenerator="NSwagCSharp" Namespace="SapService" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="5.0.11">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="NSwag.ApiDescription.Client" Version="13.13.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="System.Text.Json" Version="5.0.2" />
  </ItemGroup>

</Project>



Solution 1:[1]

Check dependencies: https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/

this version requires for you to use one of:

  • .net framework >= 4.6.1
  • .net standard >= 2.0
  • .net core 5.0

so if you have requirements for netcoreapp3.1 you need to use the version 3.1.20 or lower

Solution 2:[2]

for my project when I upgrade .net version from 4.5 to 4.6 it' Ok

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 T. Nielsen
Solution 2 Reza Zanganeh