【发布时间】:2017-05-19 17:12:38
【问题描述】:
出于某种原因,我必须更新 Microsoft.IdentityModel.Clients.ActiveDirectory v3.13.9 和 Microsoft.Azure.KeyVault v2.0.6。它总是会因缺少程序集引用而引发异常,但将我不允许使用的 Microsoft.IdentityModel.Clients.ActiveDirectory 降级到 v2.28.4 可以解决此问题 known issue。
这是一个例外:
InnerException:
HResult=-2146233036
Message=The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin' threw an exception.
Source=Microsoft.IdentityModel.Clients.ActiveDirectory
TypeName=Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin
StackTrace:
at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin.get_Logger()
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext..cctor()
InnerException:
ErrorCode=assembly_not_found
HResult=-2146233088
Message=Assembly required for the platform not found. Make sure assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.12.0.827, Culture=neutral, PublicKeyToken=31bf3856ad364e35' exists
Source=Microsoft.IdentityModel.Clients.ActiveDirectory
StackTrace:
at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin.LoadPlatformSpecificAssembly()
at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin.InitializeByAssemblyDynamicLinking()
at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin..cctor()
InnerException:
FileName=Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.12.0.827, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog==== Pre-bind state information ===
代码sn-ps:
protected KeyVaultBase(string clientId, string clientSecret)
{
if (string.IsNullOrWhiteSpace(clientId))
{
throw new ArgumentNullException(nameof(clientId));
}
if (string.IsNullOrWhiteSpace(clientSecret))
{
throw new ArgumentNullException(nameof(clientSecret));
}
this.KeyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
(authority, resource, scope) => GetAccessToken(authority, resource, scope, clientId, clientSecret)
)
);
}
private static async Task<string> GetAccessToken(string authority, string resource, string scope, string clientId, string clientSecret)
{
var authnContext = new AuthenticationContext(authority);
var clientCredential = new ClientCredential(clientId, clientSecret);
var result = await authnContext.AcquireTokenAsync(resource, clientCredential);
if (result == null)
{
throw new InvalidOperationException("Failed to obtain the JWT token");
}
return result.AccessToken;
}
执行var authnContext = new AuthenticationContext(authority); 时抛出异常。
有没有人知道任何解决方案/解决方法可以在不降级的情况下解决此问题?
【问题讨论】:
-
当您右键单击项目并选择属性时,您当前的项目是在哪个版本的 .net 框架下构建的..?
-
.NET Framework 4.5.2
-
您是否允许将项目更改为使用不同版本的 .net 框架,例如降至 4.0 您还可以做的是将引用节点中的 dll 更改为
CopytoLocal=值从 false为真 -
没有。我的团队主要使用 .NET 4.5 和 4.5.2。
-
那么这可以是 GAC 的吗?这几乎听起来像是一个 GAC 问题..
标签: c# .net azure nuget azure-keyvault