-1

I have a .NET Standard project that uses the library "RethinkDb.Driver" but when I start my project and I have the following error

Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies

However, my project already uses Newtonsoft.Json 12.0.3. I however can't go back to the version 10.0.0 because I'm also using another library that needs the latest version.
I checked my .csproj and the PackageReference is here, pointing to the version 12.0.3
I also already tried things like cleaning the NuGet cache but it didn't fix anything.

avocadoLambda
  • 1,332
  • 7
  • 16
  • 33
Xwilarg
  • 364
  • 1
  • 6
  • 16
  • There are plenty solutions for this using `` – Selvin Jul 02 '20 at 12:02
  • Check this question, looks like possible duplicate: https://stackoverflow.com/questions/44053187/could-not-load-file-or-assembly-system-componentmodel-annotations-version-4-1?rq=1 – Amadare42 Jul 02 '20 at 12:03

1 Answers1

2

You have to use assembly redirect.

You have to put it in your config file. It will be app.config in library and executable project, and web.config if it's a web project

That is a directive to dotnet to resolve this dependency to newVersion

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-12.0.3.0" newVersion="12.0.3.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>
Ygalbel
  • 5,214
  • 1
  • 24
  • 32