【问题标题】:Azure KeyVault: Exceptions when using GetSecretAsyncAzure KeyVault:使用 GetSecretAsync 时出现异常
【发布时间】:2023-03-19 05:32:01
【问题描述】:

在开发模式下,在我的本地机器VS2017 15.7.5上,我正在使用

  • Asp.Net MVC 核心 2.1
  • Azure KeyVault 3.0.0
  • AppAuthentication 1.1.0-预览版

我已经建立了一个单独的项目,用于从保险库中获取机密、添加日志记录和其他内容。我从我的 MVC 项目中引用了该项目。

当我启动网站时,我得到:

Exception thrown: 'System.IO.FileLoadException' in Microsoft.AspNetCore.Hosting.dll

我无法追踪。

{编辑:我发现了这个,它在CSPROJ 中是一个不好的参考。其他一切都保持不变。}

我像这样实例化AzureServiceTokenProvider

_provider = new AzureServiceTokenProvider();
_client = new KeyVaultClient(new KeyVaultClient
                 .AuthenticationCallback(_provider.KeyVaultTokenCallback));

然后我像这样使用它:

try
    {
        var secretBundle = await _client
           .GetSecretAsync(_config[$"{SecretUrlsKey}:{secretName}"])
           .ConfigureAwait(false);

        Debug.WriteLine("Secret retrieved from vault ...");

        _secretCache.Add(secretName, secretBundle.Value);
        return secretBundle?.Value;
     }
catch (Exception e)
...

然后我收到一连串错误(没有一个错误返回到我的代码中)。像这些:

Exception thrown: 'Microsoft.Rest.TransientFaultHandling.HttpRequestWithStatusException' in Microsoft.Rest.ClientRuntime.dll
Exception thrown: 'Microsoft.Rest.TransientFaultHandling.HttpRequestWithStatusException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Sockets.SocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProviderException' in Microsoft.Azure.Services.AppAuthentication.dll
Exception thrown: 'Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProviderException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProviderException' in System.Private.CoreLib.dll

最终我得到了我正在寻找的价值,但这似乎有点不稳定。

FWIW,我将它部署到 Azure 的成功率为零。

有人对此有任何想法吗?

TIA

【问题讨论】:

  • 我忘了提到我是如何修复文件未找到问题的。这样做:C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional gacutil -if Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.Shell.Interop.8.0.dll

标签: azure-keyvault


【解决方案1】:

至于第二个问题,它发生在两台不同的机器上。由于没有真正的科学分析(没有时间),我的直觉是允许您在安装时运行 VS 的 dotnet 核心更新导致了问题。

最后,我使用了Visual Studio Installer 修复选项,问题就消失了。一定有什么东西被破坏了。

不要忘记备份您的扩展程序和设置,因为修复会破坏所有这些。

Nuget 包清除和重新安装什么也没做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 2015-12-12
    • 2011-10-15
    • 2015-02-05
    相关资源
    最近更新 更多