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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Core 5.0 project references Framework 4.7.2 project and throws error in 'System.Security'.Cryptography.SHA256Cng'

(0) ShareShare
ReportReport
Posted on by 5

The framework project is running a method that gets an access token for AAD to dynamics 365 CRM and returns it as a request header. The error from running the GetAuthHeader is

One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.)

I've tried researching it and I'm wondering if I'm using the wrong framework version? Any help is greatly appreciated. Both methods shown below are using Framework 4.7.2.

I'm using the PowerApps-Samples, specifically the CDSWebApiService at https://github.com/microsoft/PowerApps-Samples/tree/master/cds/webapi/C#/CDSWebApiService

The method below throws an error when called:

private AuthenticationHeaderValue GetAuthHeader()
        {
            AuthenticationResult authResult;
            if (_credential == null)
            {
                authResult = _authContext.AcquireTokenAsync(
                    serviceUri, clientId, 
                    new Uri(redirectUrl), 
                    new PlatformParameters(PromptBehavior.Auto)).Result;
            }
            else
            {
                authResult = _authContext.AcquireTokenAsync(serviceUri, clientId, _credential).Result;
            }
            return new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
        }

The method calling this is shown below. The call to the above GetAuthHeader is what throws the exception:

protected override Task SendAsync(
                  HttpRequestMessage request, CancellationToken cancellationToken)
        {
            try
            {
                request.Headers.Authorization = GetAuthHeader(); //This throws the error
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return base.SendAsync(request, cancellationToken);
        }

------------------------------------

code from CRM tools.

I have the same question (0)

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 146 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 59

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans