Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

610
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda