JWT error for PS-MsolService in .NET API

Yekez 1 Reputation point
2022-01-14T16:24:22.903+00:00

Hello everyone,

I am trying to automate our users for o365 and I need to connect to MsolService via powershell in my .net project. But I get following error:

System.Management.Automation.CmdletInvocationException: Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=6.15.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
 ---> System.TypeLoadException: Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=6.15.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at Microsoft.Online.Administration.Automation.ConnectMsolService.MsolCmdletProcessRecord()

Any help is appreciated. Thank you.

Developer technologies ASP.NET ASP.NET Core
Windows for business Windows Server User experience PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,916 Reputation points
    2022-01-17T10:49:56.86+00:00

    Hello Yekez,

    I would recommend to:

    -Upgrade System.IdentityModel.Tokens.Jwt nuget package to latest version
    -Upgrade Microsoft.Owin.Security.Jwt nuget package to latest version
    -Install the latest preview of Microsoft.Owin package (4.0.0)


    --If the reply is helpful, please Upvote and Accept as answer--


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.