question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile Error: SecurityTokenExpiredException exists in both 'Microsoft.IdentityModel.Tokens' and 'Microsoft.IdentityModel'

See original GitHub issue

Hi there,

Looking for some guidance around this particular compilation issue.

Packages in use that are conflicting on the type "SecurityTokenExpiredException " which I’m catching in try/catch block:

  <package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net45" />
  <package id="Microsoft.IdentityModel.Tokens" version="5.2.4" targetFramework="net45" />

These packages are referenced by the SharePointPnPCoreOnline - however I don’t think the problem lies with them?

Those packages are:

  <package id="SharePointPnP.IdentityModel.Extensions" version="1.2.4" targetFramework="net45" />
  <package id="SharePointPnPCoreOnline" version="3.1.1809" targetFramework="net45" />

Example code usage:

            bool contextTokenExpired = false;

            try
            {
                if (SharePointContextProvider.Current.GetSharePointContext(httpContext) != null)
                {
                    return RedirectionStatus.Ok;
                }
            }
            catch (SecurityTokenExpiredException)
            {
                contextTokenExpired = true;
            }

Full error:

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0433	The type 'SecurityTokenExpiredException' exists in both 'Microsoft.IdentityModel.Tokens, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'	...	...\SharePointContext.cs	333	N/A

Any guidance would be greatly appreciated!

Cheers

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
easyveaziecommented, Nov 1, 2018

As a bandaid, I’m making the catch less specific and invalidating the token on any exception.

            try
            {
                if (SharePointContextProvider.Current.GetSharePointContext(httpContext) != null)
                {
                    return RedirectionStatus.Ok;
                }
            }
            catch
            {
                contextTokenExpired = true;
            }
1reaction
z0nekillcommented, Sep 18, 2018

Hey @brentschmaltz,

<package id="SharePointPnPCoreOnline" version="3.1.1809" targetFramework="net45" />

Is the core nuget package that references the two conflicting IdentityModel packages.

Is that what you’re looking for?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The type 'SecurityTokenDescriptor' exists in both 'Microsoft. ...
The type 'SecurityTokenDescriptor' exists in both 'Microsoft.IdentityModel.Tokens, Version=5.6.0.0' and 'Microsoft.IdentityModel, Version=3.5.0.
Read more >
How To use GetAppOnlyAuthenticatedContext when ...
You can handle this in one of two ways: 1. Fully qualify the type. catch (Microsoft.IdentityModel.Tokens.SecurityTokenExpiredException) ...
Read more >
SecurityTokenExpiredException Class
Initializes a new instance of the SecurityTokenExpiredException class using the specified error message. SecurityTokenExpiredException(String, Exception).
Read more >
The type 'SecurityTokenDescriptor' exists in both 'Microsoft ...
Coding example for the question The type 'SecurityTokenDescriptor' exists in both 'Microsoft.IdentityModel.Tokens, Version=5.6.0.0' and 'Microsoft.
Read more >
SecurityTokenExpiredException reported in Azure #10625
That error is thrown by System.IdentityModel.Tokens.Jwt.ValidateToken method, (see:https://docs.microsoft.com/en-us/dotnet/api/system.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found