We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

TypeLoadException - JwtSecurityTokenHandler


Today I tried to get a system user token of a custom app we develop for one of our customers (StoecklinERPLink). So I downloaded the online sample from https://github.com/SuperOffice/SuperOffice.DevNet.Online, set .NET 4.7.2 framework for all projects, updated all NuGet packages, adjusted the web.config to the custom app and try to run the project SuperOffice.DevNet.Online.SystemUser.Mvc. I did that a few times already, although with older versions.

This time, however, I get a System.TypeLoadException in method TryLogin when the token gets validated:

var superIdClaims = tokenHandler.ValidateToken(token, typedTokenType);

It says
Message = The type "System.IdentityModel.Tokens.JwtSecurityTokenHandler" in the assembly "System.IdentityModel.Tokens.Jwt, Version =, Culture = neutral, PublicKeyToken = 31bf3856ad364e35" could not be loaded.
Source = SuperOffice.SuperID.Client
(Google tranlsation from German)

Then I analyzed the assembly System.IdentityModel.Tokens.Jwt.dll.
Type "System.IdentityModel.Tokens.JwtSecurityTokenHandler" does not exists, it should probably be "System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler".

System.IdentityModel.Tokens.JwtSecurityTokenHandler ==> not ok
System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler ==> ok

I also looked up earlier versions (5.0.0, 5.2.1) but the all have System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler only.
Any ideas?

Best regards

PS. tokenHandler in the code line above is of type SuperOffice.SuperID.Client.Tokens.SuperIdTokenHandler which is in assembly "\packages\SuperOffice.Crm.Online.Core.4.0.6985.1226\lib\net45\SuperOffice.SuperID.Client.dll".

RE: TypeLoadException - JwtSecurityTokenHandler

Installing version seems to solve the issue.

Using NuGet package manager console execute “Install-Package System.IdentityModel.Tokens.Jwt -Version”. After that, SuperIdTokenHandler.ValidateToken does no longer throw an exception.

Av: Marc Eberhard 1. mai 2019

RE: TypeLoadException - JwtSecurityTokenHandler


Thats correct. Version 4.x and 5.x of the nuget package System.IdentityModel.Tokens.Jwt are API incompatible. (Using assembly redirects will not work).  

We have updated the relevant packages internally including SuperIdTokenHandler, but we haven't pushed new updates to the nuget servers. I'm not sure when we will be releasing it to the nuget servers. I will talk to Tony about it. 



Av: Hans Oluf Waaler 2. mai 2019

RE: TypeLoadException - JwtSecurityTokenHandler

The latest new version of the packages (supporting System.IdentityModel.Tokens.Jwt 5.x) requires the Online Environment to be updated.  We are now starting to wrap up a new version and hope we can update the environment and release new packages within a couple of weeks.

Av: Jens M. Glattetre 6. mai 2019

RE: TypeLoadException - JwtSecurityTokenHandler


Did this get updated?  I get the same message if i use v5.6 now: 
{"Could not load type 'System.IdentityModel.Tokens.JwtSecurityTokenHandler' from assembly 'System.IdentityModel.Tokens.Jwt, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.":"System.IdentityModel.Tokens.JwtSecurityTokenHandler"} 


Av: Eivind Johan Fasting 24. okt 2019

RE: TypeLoadException - JwtSecurityTokenHandler


I'm facing the same problem, any updates on this?



Av: Gunnar Stensby 24. okt 2019

RE: TypeLoadException - JwtSecurityTokenHandler


Nothing new has happened on this front, but is on the backlog. That said, I must add that there is nothing SuperOffice specific or magical about these libraries. On one hand these are just helper libraries that help sign and validate tokens - which one could argue all developers should inherently know how to do anyway. On the other is helping those in need just reference them and get on with it. 

Whether they get updated or pushed onto github, I will try and prioritize this.

Av: Tony Yates 25. okt 2019

RE: TypeLoadException - JwtSecurityTokenHandler


My issue was that I already had parts of my code using v5.6 (similar openId towards an onsite API), so when i downgraded those parts stopped working. 
I found this thread a couple of weeks back and (silly me) assumed (without testing) that this was now 'done'..

No problem, i got everthing working with a little magic in the end ;) 


Av: Eivind Johan Fasting 25. okt 2019

RE: TypeLoadException - JwtSecurityTokenHandler

OK, so Online nuget pages have been updated and are available:

The online environment is using System.IdentityModel.Tokens.Jwt, Version=5.4


Av: Tony Yates 3. des 2019

RE: TypeLoadException - JwtSecurityTokenHandler

Great work, Tony! :) 

Av: Eivind Johan Fasting 12. des 2019