web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Could not load type 'System.IdentityModel.Tokens.Jwt.JwtSecurityToken'

(0) ShareShare
ReportReport
Posted on by
Hi Folks i'm trying to generate JWT token.
 
for that i created classLibrary and used it in d365 fo projects reference to generate the JWT token but it is showing below error.

Could not load type 'System.IdentityModel.Tokens.Jwt.JwtSecurityToken' from assembly 'System.IdentityModel.Tokens.Jwt, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
 
the code i used in DLL is 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Claims;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;
namespace JWT
{
    public class getToken
    {
        
        public string getJWTToken(string apiKey, string secret)
        {
           
            string tokenCreationTime = DateTimeOffset.Now.ToUnixTimeSeconds().ToString();
            //Your payload
            var claims = new[]
            {
            new Claim(/iss/,apiKey),
            new Claim(/iat/, tokenCreationTime)
            };
            //Your secret key for signing the token
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(secret);
            string base64String = Convert.ToBase64String(bytes);

            var key = new SymmetricSecurityKey(Convert.FromBase64String(base64String));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            var token = new JwtSecurityToken(
                issuer: apiKey,
                claims: claims //,
                 //expires: DateTime.Now.AddHours(1), // Adjust as needed
                signingCredentials: creds
            );
            string tokenString = new JwtSecurityTokenHandler().WriteToken(token);
            return tokenString;

        }
    }
}
and the code i used in x++ is
 
using JWT;
internal final class JWTGenerate
{
    public static void main(Args _args)
    {
        JWT.getToken getToken;
       
        getToken = new JWT.getToken();

        str    api = '********************',
            secret = '********************';
 
        str token = getToken.getJWTToken(api,secret).ToString();
      
        info(strFmt(/%1/, token));
    }
}
 
showing i  tried same code in C# console app it is working perfectly.
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,684 Most Valuable Professional on at
    F&O indeed doesn't contain this assembly. Add it to the bin folder of your model and add a reference to it.
  • AliGul Profile Picture
    66 on at
    Hi everybody,

    I am facing same issue, has anyone resolved this? please help.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 681 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 598 Super User 2026 Season 1

#3
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 579

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans