Error trying to generate token using .NET JWT library : <p>I'm trying to use package System.IdentityModel.Tokens.Jwt to generate a token. I found some code samples online, was pretty straightforward, but then I'm running into an error that I can't figure out. Here's the code I'm using (has been modified slightly for brevity):</p>

<pre><code>&lt;%@ Application Language="C#" %&gt;
&lt;%@ Import Namespace="System" %&gt;
&lt;%@ Import Namespace="System.Text" %&gt;
&lt;%@ Import Namespace="System.Reflection" %&gt;
&lt;%@ Import Namespace="System.Collections" %&gt;
&lt;%@ Import Namespace="System.IdentityModel.Tokens" %&gt;
&lt;%@ Import Namespace="System.IdentityModel.Tokens.Jwt" %&gt;
&lt;%@ Import Namespace="System.Security.Claims" %&gt;
&lt;%@ Import Namespace="System.IdentityModel.Protocols.WSTrust" %&gt;

&lt;script runat="server"&gt;
    public class TestClass
    {
        public static string GetJwtToken()
        {
            var tokenHandler = new JwtSecurityTokenHandler();
            var input = "anyoldrandomtext";
            var securityKey = new byte[input.Length * sizeof(char)];
            Buffer.BlockCopy(input.ToCharArray(), 0, securityKey, 0, securityKey.Length);
            var now = DateTime.UtcNow;
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new[]
                {
                new Claim( ClaimTypes.UserData,
                "IsValid", ClaimValueTypes.String, "(local)" )
              }),
                TokenIssuerName = "self",
                AppliesToAddress = "https://www.mywebsite.com",
                Lifetime = new Lifetime(now, now.AddMinutes(60)),
                SigningCredentials = new SigningCredentials(new InMemorySymmetricSecurityKey(securityKey),
                  "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",
                  "http://www.w3.org/2001/04/xmlenc#sha256"),
            };

            var token = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);

            return tokenString;
        }
    }
&lt;/script&gt;
</code></pre>

<p>I keep getting the following error at line 113 (var token = tokenHandler.CreateToken(tokenDescriptor);):</p>

<p><em>Argument 1: cannot convert from 'System.IdentityModel.Tokens.SecurityTokenDescriptor' to 'Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor'</em></p>

<p>But I've seen many examples online doing things exactly as I've done them. I also ran into this article (<a href="https://msdn.microsoft.com/en-us/library/jj157089(v=vs.110).aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/jj157089(v=vs.110).aspx</a>) that states the following:</p>

<blockquote>
  <p>In WIF 3.5, all of the WIF classes were contained in the
  Microsoft.IdentityModel assembly
  (microsoft.identitymicrosoft.identitymodel.dll). In WIF 4.5, the WIF
  classes have been split across the following assemblies: mscorlib
  (mscorlib.dll), System.IdentityModel (System.IdentityModel.dll),
  System.IdentityModel.Services (System.IdentityModel.Services.dll), and
  System.ServiceModel (System.ServiceModel.dll).</p>
  
  <p>The WIF 3.5 classes were all contained in one of the
  Microsoft.IdentityModel namespaces; for example,
  Microsoft.IdentityModel, Microsoft.IdentityModel.Tokens,
  Microsoft.IdentityModel.Web, and so on. In WIF 4.5, the WIF classes
  are now spread across the System.IdentityModel namespaces, the
  System.Security.Claims namespace, and the System.ServiceModel.Security
  namespace. In addition to this reorganization, some WIF 3.5 classes
  have been dropped in WIF 4.5.</p>
</blockquote>

<p>I tried for debugging sake to switch to use the Microsoft.* namespace for the SecurityTokenDescriptor, and then I get another series of errors saying TokenIssuerName, AppliesToAddress, and Lifetime aren't valid properties for that class. Yet when I look at the docs online, seems like those properties do exist on Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor. Yet in my Visual Studio, when I do Go to Definition for that class, they're not there, leading me to believe that there's some kind of configuration issue in my Visual Studio. In my package manager, it shows I have Microsoft.IdentityModel.Tokens v5.0.0 installed. I also changed the project to .NET framework 4.5.1 since the JWT library requires it. Beyond that, I don't know where else to look.</p>
