我想将我在 ASP.NET Core 1.0 上的项目与 Microsoft Azure KeyVault 集成。但似乎 Microsoft.Azure.KeyVault 包与“netcoreapp1.0”框架不兼容(我尝试使用 NuGet 包管理器下载包并显示“不兼容包”错误消息)。因此,我在此块中显示的 project.json 中导入“net451”框架:
"frameworks": {
"netcoreapp1.0": {
"imports": [
"net451",
"dotnet5.6",
"portable-net45+win8"
]
}
},
导入“net451”框架后,错误现在消失了。现在我想启动这个块中显示的新 KeyVaultClient 类:
public void GetKeyVaultSecret()
{
var keyVaultClient = new KeyVaultClient(this.GetTokenAsync);
// ....
}
private async Task<string> GetTokenAsync(string authority, string resource, string scope)
{
var authenticationContext = new AuthenticationContext(authority);
var authenticationResult =
await authenticationContext.AcquireTokenAsync(resource, this.clientAssertionCertificate);
return authenticationResult.AccessToken;
}
问题是我收到了这个错误消息this.GetTokenAsync
,我已经搜索了几个小时的解决方案,但没有任何运气:Argument 1:cannot convert from 'method group' to 'KeyVaultClient.AuthenticationCallback'
如果我改变
var keyVaultClient = new KeyVaultClient(this.GetTokenAsync);
至:
var keyVaultClient = new KeyVaultClient((authority, resource, scope) => this.GetTokenAsync(authority, resource, string.Empty));
我仍然收到错误消息:Cannot convert lambda expression to type 'KeyVaultClient.AuthenticationCallback' because it is not a delegate type
有人知道如何解决这个问题吗?谢谢。
问候, 阿尔文