【发布时间】:2018-01-30 04:34:55
【问题描述】:
我正在尝试使用 Microsoft.Azure.Management.Compute ComputeManagementClient Usage 属性来列出通过 Azure 的所有资源使用情况。
我专门使用Usage.ListAsync() 来实现这一点。根据documentation,这是一种扩展方法。
我在使用以下创建 ComputeManagementClient 的实例后调用扩展方法:
public async Task<IComputeUsage> GetResourceUsage(int customerId)
{
var azureClient = _dbContext.CreateAzureComputeClient(customerId);
var usageReport = await azureClient.Usage.ListAsync();
}
但是,这将返回以下错误:
'IUsageOperations' does not contain a definition for Listasync and the best extention method overload ProvidersOptionsExtensions.ListAsync... Requires a receiver of type 'IProvidersOperations'。
这是一个错误,还是我错误地调用了该方法?
编辑:我在代码中使用了正确的命名空间:
using System.Threading.Tasks;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.Compute.Fluent;
然而,VS2017 并没有指明命名空间的使用(灰色,而不是黑色)。
【问题讨论】:
-
要使用扩展方法,您需要命名空间:
using Microsoft.Azure.Management.Compute。除此之外,他们的文档中没有无参数的ListAsync。 -
@CodingYoshi 虽然这是我的第一个,但我在我的代码中使用了这个命名空间。
标签: c# .net azure asp.net-core-2.0