title: MSOnline Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken'
body: <p>I have an asp.net core web application that uses the <code>MSOnline</code> PowerShell module to interact with Office 365.  When the <code>Connect-MsolService</code> cmdlet executes to authenticate with Office 365 I'm getting the following error.  </p>
  
  <blockquote>
    <p>Could not load type 'System.IdentityModel.Tokens.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=5.1.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.</p>
  </blockquote>
  
  <p>When running the same logic in another project via a unit test I do not get the error, the code executes as expected.  Both the test project and the web project are using the same version (5.1.5) of the <code>System.IdentityModel.Tokens.Jwt</code> assembly so I don't understand why I'm getting this error when that logic executes in the web app.  </p>
  
  <p>I've read that a solution is to downgrade to v4 of the <code>System.IdentityModel.Tokens.Jwt</code> assembly but I know it works with 5.1.5 because my tests are passing.  Besides, that's not an option for me because some of the aspnetcore assemblies require v5.  Does anyone understand why this would happen in the asp.net core web app or know a solution that doesn't require downgrading the assembly?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>It looks like my binding redirect is causing the problem.  If I add the following to the app.config file in my test project it produces the error.  This is very odd because 5.1.5 is the version of <code>System.IdentityModel.Tokens.Jwt</code> that's referenced, it's as if a different version is being used by default.</p>
  
  <pre><code>  &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-5.4.0.0" newVersion="5.1.5.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
  </code></pre>