Error loading System.IdentityModel.Tokens.Jwt dll in WebAPI2 project

后端 未结 2 1267
小蘑菇
小蘑菇 2021-02-07 10:54

I am getting the below error in WebApi2 project:

Could not load file or assembly \'System.IdentityModel.Tokens.Jwt, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf

2条回答
  •  清歌不尽
    2021-02-07 11:23

    In my case adding binding redirect helps.

    I have a windows service application, which consumes Microsoft.Owin.Security.Jwt (3.0.1) and System.IdentityModel.Tokens.Jwt (4.0.20622.1351); As I can see, Microsoft.Owin.Security.Jwt (3.0.1) has reference to the System.IdentityModel.Tokens.Jwt (4.0.0) [katanaproject]:

    
      False
      ..\..\packages\System.IdentityModel.Tokens.Jwt.4.0.0\lib\net45\System.IdentityModel.Tokens.Jwt.dll
    
    

    The exception mentioned above has ocured exactly when the call was made:

    app.UseJwtBearerAuthentication(new CustomJwtOptions());
    

    So I can conclude that package Microsoft.Owin.Security.Jwt (3.0.1) tries to load System.IdentityModel.Tokens.Jwt (4.0.0)

    EDIT

    We have simple .net app, which is distributed with app.exe.config file. Modifying the file helps to solve the problem mentioned:

    
    
    
    
        
        
            
            
                
                
            
            
        
        
    
    
    
    

提交回复
热议问题