Core 5.0 project references Framework 4.7.2 project and throws'System.Security.Cryptography.SHA256Cng' error
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, specifcally the CDSWebApiService at https://github.com/microsoft/PowerApps-Samples/tree/master/cds/webapi/C%23/CDSWebApiService
Method below throws 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<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
try
{
request.Headers.Authorization = GetAuthHeader(); //This throws the error
}
catch (Exception ex)
{
throw ex;
}
return base.SendAsync(request, cancellationToken);
}
In short, it's not supported in .NET Core, You probably should update your .NET version/runtime.