System.IdentityModel.Tokens.Jwt Error

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
trevor530
Posts: 25
Last visit: Mon Feb 12, 2024 9:27 am

System.IdentityModel.Tokens.Jwt Error

Post by trevor530 »

Product, version and build: Powershell Studio, 5.8.213
Operating system: Windows 11
PowerShell version(s): 7.3.0

It all started with Microsoft no longer allowing Basic Auth to Exchange Online....

We are getting an error when we attempt to connect to Exchange Online using the following command:

Connect-ExchangeOnline -AppId $textboxAppID.Text -CertificateThumbprint $textboxCertThumbprint.Text -Organization $textboxTenantName.Text -ErrorAction Stop

The error is:

Could not load file or assembly 'System.IdentityModel.Tokens.Jwt,
ERROR: | Version=6.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621)

The app we are rebuilding is a GUI app. I have seen posts in the forums about the ExchangeOnline module having issues with GUI based apps but some posters say it works in Powershell 7 with the latest version of ExchangeManagement.

We are:
Running Powershell Studio using Powershell 7
#Requires -Version 7
ExchangeOnline module is version 3
.NET framework is up-to-date
Windows is up-to-date
User avatar
brittneyr
Site Admin
Posts: 1649
Last visit: Mon Mar 18, 2024 1:47 pm
Answers: 38
Been upvoted: 30 times

Re: System.IdentityModel.Tokens.Jwt Error

Post by brittneyr »

From your error message, you are missing a required file. Please make sure you have all required assemblies.

The posts you are seeing are about threading issues which causes the dialog to hang. This does not appear to be the same issue.
Brittney
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1649
Last visit: Mon Mar 18, 2024 1:47 pm
Answers: 38
Been upvoted: 30 times

Re: System.IdentityModel.Tokens.Jwt Error

Post by brittneyr »

[Topic was moved by moderator]
Brittney
SAPIEN Technologies, Inc.
User avatar
trevor530
Posts: 25
Last visit: Mon Feb 12, 2024 9:27 am

Re: System.IdentityModel.Tokens.Jwt Error

Post by trevor530 »

What required assemblies am I missing? How can I find out?
User avatar
trevor530
Posts: 25
Last visit: Mon Feb 12, 2024 9:27 am

Re: System.IdentityModel.Tokens.Jwt Error

Post by trevor530 »

We figured it out. It seems that ExchangeManagementOnline v3 module has a conflict with Microsoft.Graph v1.19 module. It appears the issue is resolved in the Microsoft.Graph v2 Preview.
User avatar
trevor530
Posts: 25
Last visit: Mon Feb 12, 2024 9:27 am

Re: System.IdentityModel.Tokens.Jwt Error

Post by trevor530 »

Turns out this is still an error. We can run the commands in the Powershell 7 console but not in our GUI app.
User avatar
brittneyr
Site Admin
Posts: 1649
Last visit: Mon Mar 18, 2024 1:47 pm
Answers: 38
Been upvoted: 30 times

Re: System.IdentityModel.Tokens.Jwt Error

Post by brittneyr »

If you are getting a different error, please post the new error message here.

If it's the same error, make sure your versions of assemblies loading match the version in the error message.
Your previous error was unable to find this assembly:
https://www.nuget.org/packages/System.I ... Jwt/6.21.0

If you have updated your ExchangeOnlineManagement module, this version may have changed.

The FileList in the psd1 shows the assemblies it is loading:
https://www.powershellgallery.com/packa ... ement.psd1

Are you packaging your script as an executable? If so, you may need to have these (or some of these) assemblies located in the folder your executable is in.
Brittney
SAPIEN Technologies, Inc.
User avatar
trevor530
Posts: 25
Last visit: Mon Feb 12, 2024 9:27 am

Re: System.IdentityModel.Tokens.Jwt Error

Post by trevor530 »

We figured it out... again. It has to do with a conflict between ExchangeManagementOnline v3.10 and Microsoft.Graph preview 2 update 4. We found no conflict between Exchange v3.0 and Graph 2 update 4.
This topic is 1 year and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked