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

Notifications

Announcements

No record found.

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
    237,976 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans