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.