Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

609
Views
Conflict of version between System.Text.Json and System.Runtime.CompilerServices.Unsafe when using JsonSerializer

Our C# application is using .Net Framework 4.7.2 and we're trying to implement JsonSerializer in System.Text.Json. We are able to build the solution without any issues but when we try to run the application we get the following error

Resolve failed: System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Caught exception while running: Main System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at System.Span`1..ctor(T[] array) at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, Type returnType, JsonSerializerOptions options) at Project.Class1.Main(String[] args) in D:\Project\Class1.cs:line 36

Looking at the version of System.Rutime.CompilerServices.Unsafe that is installed in NuGet, it's 5.0.0 and inside our app.config file, we have the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Now, since 4.0.4.1 is within the range of the oldVersion, I would assume that it should be redirecting to 5.0.0.0 instead of looking for 4.0.4.1, but I must be mistaken. I also tried to change the oldVersion to "4.0.4.1" but that did not help.

If I try to change the version of System.Runtime.CompilerServices.Unsafe to the package version 4.5.3, which corresponds to version 4.0.4.1, then System.Text.Json needs to downgraded from 5.0.2 to 2.0.0.11. This version does not contain JsonSerializer so it won't work with our application.

Is there a way that we could successfully redirect from looking for the old version (4.0.4.1) to looking for the latest version that is installed (5.0.0.0)? Any feedback or suggestions is appreciated!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!