简体   繁体   中英

Retrieving App Service list from Azure using C# Microsoft.Azure.Management.Fluent is resulting in 'this.Client.SubscriptionId' cannot be null

I'm attempting to use the Fluent libraries in a C# web application in order to retrieve a list of application services from Azure.

My problem is that function calls to do so are throwing an exception "'this.Client.SubscriptionId' cannot be null. " .

The way I'm authenticating is using the FromServicePrinciple call:

AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(ApplicationID, AuthKey, TenantID, AzureEnvironment.AzureGlobalCloud);

Then creating an interface;

IAzure az = Azure.Configure().Authenticate(credentials).WithDefaultSubscription();

As far as I can tell, the applicationid and tenantid are correct, because otherwise I get a different exception that says the application cannot be found. I also cant see how I could have gotten the authkey wrong since I just created it.

When I examine az.SubscriptionId at this point it is null, which I'm guessing it shouldn't be.

So, when I call

var appservicelist = az.AppServices.List();

or

var webapplist = az.WebApps.List();

I get the exception.

Does anyone have any idea what the cause of this is, or what I need to change in Azure in order for this to work?

Thanks.

Please ensure you have subscription in your tenant. If you don't set default subscription, you could set subscription in your code.

IAzure az = Azure.Configure().Authenticate(credentials).WithSubscription("3b4d41fa-****-4bc7-bc11-***");

Note: Replace your subscription id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM