'Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=5.2.0.0

I am trying to add OWIN JWT into webapi project using VS 2015. The reference shows Microsoft.Owin.Security.Jwt, Version=4.0.0.0 and Microsoft.IdentityModel.Tokens Version=5.3.0.0. Below is the error when running. I could not find 5.2.0.0 in the source code.

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.IdentityModel.Tokens, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Users/xxx/Documents/xxx/WebApi/
LOG: Initial PrivatePath = C:\Users\xxx\Documents\xxx\WebApi\bin
Calling assembly : Microsoft.Owin.Security.Jwt, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

Any idea please?



Solution 1:[1]

First, you should understand that the exception occurred is not restricted to Microsoft.IdentityModel.Tokens assembly, nor the Visual Studio Version. the problem is popular with the assembly referencing.

the popular reason is: you are referencing in the project to a version different than in the "DLL" package used in the execution (bin folder). However, I think this farther than getting happened manually.

1- I can guess based on the assembly name. that you have more than one project in your solution and you lastly installed the assembly using NuGet with a version higher than in other projects (of course using NuGet )

Try to verify the installed package in all your projects and update all of them to the latest one Version=5.3.0.0.

Another potential reason is: this package requires the Microsoft.IdentityModel.Logging try to do the same operation explained above in point 1.

Solution 2:[2]

All packages related *.Owin were updated and fixed for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AbuDawood
Solution 2 ddagsan