title: Cannot Load Assemblies For .Net Standard library (System.Text.Json)
body: <p>I am writing a .Net Standard 2.0 library that will be used by a binary PowerShell module. The library will be basically an API client with a lot of classes for dealing with the JSON responses. Prior to trying to deserialise the strings, I confirmed that the API was providing the JSON encoded string without issue.</p>
  
  <p>As it was <a href="https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-overview" rel="noreferrer">compatible</a> with .Net Standard 2.0 when using the NuGet package, I thought I would try switching to System.Text.Json, rather than using NewtonSoft. However, it does not seem to have the version of particular assemblies it requires on certain platforms.</p>
  
  <p><strong>My Environment:</strong></p>
  
  <p>Windows 10<br>
  PowerShell 5.1 Desktop<br>
  .Net Framework 4.8<br>
  PowerShell Core 6.2.2<br>
  dotnet version 3.0.100  </p>
  
  <p>On <strong>PowerShell Desktop</strong>, I get the following problems when it has to deserialise anything:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>PS dir:\&gt; Import-Module '.\file.dll'
  PS dir:\&gt; [namespace.class]::TestMethod($string, $anotherString)  # Test method to return string
  {"attribute":"value"}
  PS dir:\&gt; [namespace.class]::Method($string, $anotherString)  # Same as above, but uses System.Text.Json to deserialise
  Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system
  cannot find the file specified.
  
  # System.Buffers.dll is with the System.Text.Json package, but seems to be the wrong version
  PS dir:\&gt; (Get-Item .\System.Buffers.dll).VersionInfo.FileVersion
  4.6.26515.06
  PS dir:\&gt; [System.Reflection.Assembly]::LoadFile("$pwd\System.Buffers.dll").GetName().Version
  
  Major  Minor  Build  Revision
  -----  -----  -----  --------
  4      0      3      0
  </code></pre>
  
  <p>On <strong>PowerShell Core</strong> there the same exception for another assembly/file.</p>
  
  <pre class="lang-bsh prettyprint-override"><code>PS dir:\&gt; Import-Module '.\file.dll'
  PS dir:\&gt; [namespace.class]::Method($string, $anotherString)
  "Could not load file or assembly 'System.Text.Encodings.Web, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)"
  
  #System.Text.Encodings.Web.dll is with the System.Text.Json package and appears to be the required version...
  PS dir:\&gt; (Get-Item .\System.Text.Encodings.Web.dll).VersionInfo.FileVersion
  4.700.19.56404
  [System.Reflection.Assembly]::LoadFile("$pwd\System.Text.Encodings.Web.dll").GetName().Version
  
  Major  Minor  Build  Revision
  -----  -----  -----  --------
  4      0      5      0
  </code></pre>
  
  <p>Anyone got any advice on how I can resolve this without switching to Newtonsoft's JSON package? Falling back from System.Text.Json 4.7.1 to 4.7.0 or 4.6.0 introduces problems with other assemblies that are part of the NuGet package for System.Text.Json. I have read the advice <a href="https://github.com/dotnet/announcements/issues/31" rel="noreferrer">here</a>, but I either can't apply it here, or I simply do not understand.</p>
  
  <p>Thanks in advance. Please let me know if you require more information, I will provide it.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I updated the csproj as suggested by Gokhan</p>
  
  <pre class="lang-cs prettyprint-override"><code>&lt;PropertyGroup&gt;
    &lt;AutoGenerateBindingRedirects&gt;true&lt;/AutoGenerateBindingRedirects&gt;
    &lt;GenerateBindingRedirectsOutputType&gt;true&lt;/GenerateBindingRedirectsOutputType&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>This generated the following code in the appName.dll.config</p>
  
  <pre class="lang-cs prettyprint-override"><code>&lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
  </code></pre>
  
  <p>So the auto-generation of all the binding redirects is not working, as mentioned above there are at least two more that do not work. I would try manually creating them, but as far as I am aware, there is no source config file to put them in now. If anyone has any direction on that, I would appreciate it.</p>