框架專案正在運行一個方法,該方法將 AAD 的訪問令牌獲取到 dynamics 365 crm 并將其作為請求標頭回傳。運行 GetAuthHeader 的錯誤是
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'.)
我試過研究它,我想知道我是否使用了錯誤的框架版本?任何幫助是極大的贊賞。下面顯示的兩種方法都使用 Framework 4.7.2。
我正在使用 PowerApps-Samples,特別是https://github.com/microsoft/PowerApps-Samples/tree/master/cds/webapi/C#/CDSWebApiService上的 CDSWebApiService
下面的方法在呼叫時會拋出錯誤:
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);
}
呼叫它的方法如下所示。對上述GetAuthHeader的呼叫是引發例外的原因:
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);
}
uj5u.com熱心網友回復:
簡而言之,.NET Core 不支持它,您可能應該更新您的 .NET 版本/運行時。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/416298.html
標籤:
