Reputation: 1481
I'm trying to use the Microsoft.Azure.Management.Compute ComputeManagementClient Usage
property to list all resource usage through Azure.
I'm specifically using Usage.ListAsync()
to achieve this. According to the documentation this is an extension method.
I'm calling the extension method after creating an instance of the ComputeManagementClient using the below:
public async Task<IComputeUsage> GetResourceUsage(int customerId)
{
var azureClient = _dbContext.CreateAzureComputeClient(customerId);
var usageReport = await azureClient.Usage.ListAsync();
}
However, this is returning the following error:
'IUsageOperations' does not contain a definition for Listasync and the best extention method overload ProvidersOptionsExtensions.ListAsync... Requires a receiver of type 'IProvidersOperations'
.
Is this a bug, or am I calling the method incorrectly?
Edit: I am using the correct namespaces in my code:
using System.Threading.Tasks;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.Compute.Fluent;
However, VS2017 doesn't indicate the namespace usage (Grey, rather then black colour).
Upvotes: 0
Views: 583
Reputation: 2540
You are calling the Usage.ListAsync()
method incorrectly - it looks like a string parameter is needed:
ListAsync(IUsageOperations, String, CancellationToken)
Gets, for the specified location, the current compute resource usage information as well as the limits for compute resources under the subscription.
And indeed, in the code, it mentions that you need a location:
So update your code to be:
var usageReport = await azureClient.Usage.ListAsync("[resourceId('Microsoft.Storage/storageAccounts','examplestorage')]");
Upvotes: 1