jwt icon indicating copy to clipboard operation
jwt copied to clipboard

JWT is coupled with json 9.0.0 and not higher

Open KumarS-Naveen opened this issue 7 years ago • 16 comments

Hello Guys ,

I have installed JWT 4.0.0 version and json version 12.0.1 , but while validating tokens i am getting error saying it needs json version 9.0.0 even though i have higher version (12.0.1)

Please let me know for the solutions

KumarS-Naveen avatar Feb 05 '19 11:02 KumarS-Naveen

Hi, do you have assembly binding redirects in your Web/App.config in place? See https://stackoverflow.com/a/24461105/41956

abatishchev avatar Feb 05 '19 17:02 abatishchev

yes i do have like below:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <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.0.0" newVersion="12.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>`

KumarS-Naveen avatar Feb 06 '19 03:02 KumarS-Naveen

What exception you're getting? It should work if that's what you have.

abatishchev avatar Feb 06 '19 03:02 abatishchev

this is the error

Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

KumarS-Naveen avatar Feb 06 '19 04:02 KumarS-Naveen

Odd. Can you describe the project structure? Is this a web app, console app? .NET Framework or .NET Core?

I'd suggest to create a simple project without all the complexity of real project and try to reproduce the issue there

abatishchev avatar Feb 06 '19 16:02 abatishchev

Have you figured this out? Can I close?

abatishchev avatar Feb 18 '19 03:02 abatishchev

I have added the test project without any other Dependency it works fine , hence this can be closed.

I will have a look into the problem and provide the solution

KumarS-Naveen avatar Feb 18 '19 05:02 KumarS-Naveen

@IAm-Naveen have you figured it out? I have the same issue. Class library, loaded in winforms app. Both target FW is 4.6.2 Newtonsoft.Json version = 12.0.0.0

Exception:

Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   w JWT.Serializers.JsonNetSerializer..ctor()
   w AllegroClient.AllegroRESTClient.GetCurrentAccountID() w H:\C#\SubSync\BrokerDll\Broker\Allegro\AllegroClient\AllegroRESTClient.cs:wiersz 234
   w AllegroClient.AllegroRESTClient.GetCurrentAccountLogin() w H:\C#\SubSync\BrokerDll\Broker\Allegro\AllegroClient\AllegroRESTClient.cs:wiersz 253
   w AllegroClient.Config.ConnectionSettings.buttonRenewTokens_Click(Object sender, EventArgs ea) w H:\C#\SubSync\BrokerDll\Broker\Allegro\Config\ConnectionSettings.cs:wiersz 134

rtnet-pl avatar Sep 17 '19 14:09 rtnet-pl

@rtnet-pl I had a weird solution , When i download JWT package it didn't download json at all so what i did is to explicitly download json package with version 12. Also can you verify if all your class libraries have same version ?

KumarS-Naveen avatar Sep 17 '19 15:09 KumarS-Naveen

NuGet.exe will download and install all dependencies until is instructed to do otherwise. The package's nuspec states Newtonsoft.Json version 9.0.1 or higher. This version was selected as something not to old but not too new either (to allow clients with all old dependencies to consume the package as well).

abatishchev avatar Sep 17 '19 16:09 abatishchev

OK, i'm not that good in all the nuget dependencies stuff. I ended up by downloading JWT source, downloading all available nuget packages updates, and building my own lib. There's one thing i found. JWT for .NET 4.6 references Newtonsoft.Json.dll, but its target framework is 4.7.2. So if the host assembly target fw version is lower (4.6.2 in my case), it wont be loaded. image

rtnet-pl avatar Sep 18 '19 08:09 rtnet-pl

Target framework doesn't matter when NuGet restores packages with all its dependencies recursively. Can you again state what's the problem? I can guarantee you there are no issues from the JWT package side. But I can try to help to resolve an issue at yours.

abatishchev avatar Sep 18 '19 14:09 abatishchev

I can't tell if this was closed or not but I'm getting same error (as of 2/19/20). I have Newtonsoft.Json 12.0.3 installed, have tried 9.0.1, 10.0.1 and also letting JWT install Newtonsoft.Json for me (as a dependency) but in all cases I get the below error:

Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified. at JWT.Serializers.JsonNetSerializer..ctor() at JWT.Builder.JwtBuilder..ctor()

Is there a solution outside grabbing the source and fussing with myself?

cemerson avatar Feb 19 '20 14:02 cemerson

Hi Chris, do you have assembly binding redirects in place? Or you have an SDK-based project? Can you attach a zip with small repro or create a public repo with such?

abatishchev avatar Feb 19 '20 16:02 abatishchev

@abatishchev Sorry my project is kind of large / hard to repro. I tried grabbing this repo/source FWIW but got stuck trying to install dev packs and building the solution so I gave up. For now I had to go with jose-jwt but if I have time at some point I'll circle back and report any new findings or a sample project.

cemerson avatar Feb 19 '20 21:02 cemerson

Ok, then tell me just this:

do you have assembly binding redirects in place? Or you have an SDK-based project?

abatishchev avatar Feb 19 '20 22:02 abatishchev