微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

具有对Dynamic 365身份验证的Azure功能-无法加载类型'System.Security.Cryptography.SHA256Cng'

如何解决具有对Dynamic 365身份验证的Azure功能-无法加载类型'System.Security.Cryptography.SHA256Cng'

在尝试使用身份验证获取令牌之前,我有一个正常运行的功能/应用程序注册。我使用以下代码收到以下错误消息。

var requestedToken = authenticationResult.Result.Accesstoken;

生成idOne时出现问题,或发生了更多错误。 (无法从程序集System.Security.Cryptography.SHA256Cng中加载类型System.Core,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089

var aadInstance = "https://login.microsoftonline.com/";

string api = "https://interconservicesdev.crm.dynamics.com/api/data/v9.1";

AuthenticationParameters ap = AuthenticationParameters.CreateFromUrlAsync(
    new Uri(api)).Result;

string organizationUrl = "https://interconservicesdevdev.crm.dynamics.com";
string clientId = "SOME_CLIENT_ID";
string secertKey = "SOME_SECRET_KEY";
string tenantId = "SOME_TENANT_ID";

log.Info("Organization Url : " + organizationUrl);
log.Info("Client Id : " + clientId);
log.Info("Client Key : " + secertKey);
log.Info("Tenant Id : " + tenantId);

var clientcred = new ClientCredential(clientId,secertKey);
string combinestring = aadInstance + tenantId;
log.Info("Combine String : " + combinestring);

var authenticationContext = new AuthenticationContext(combinestring,false);

log.Info("Authority : " + authenticationContext.Authority);

//AuthenticationContext authenticationContext = new AuthenticationContext(authority,false);

var authenticationResult = authenticationContext.AcquiretokenAsync(organizationUrl,clientcred);
log.Info("Authentication Result : " + authenticationResult.IsCompleted + " " + authenticationResult.Id);

var requestedToken = authenticationResult.Result.Accesstoken;
log.Info("Requested Token : " + requestedToken);

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

service = new OrganizationWebProxyClient(GetServiceUrl(organizationUrl),new TimeSpan(0,180,0),false);
log.Info("Service : " + service.SdkClientVersion);
service.HeaderToken = requestedToken;

log.Info("Header Token : " + requestedToken);

enter image description here

enter image description here

解决方法

从VS 2017切换到2019年,我已经能够解决我的问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。