Uupss: 'this.Client.SubscriptionId' cannot be null

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric





'this.Client.SubscriptionId' cannot be null
There are few Azure SDKs, which might lead you to this error. The typical example is using of power shell. However, Azure platform provides also very powerful management SDK. One interesting example, which is still in preview, is Fluent API. This library provides a huge simplification for management of Azure resource.

Following code shows how to authenticate before using Fluent API, which creates instance of Fluent API in variable ‘azure’:

   var cred = AzureCredentials.FromServicePrincipal(clientId,
clientSeecret, tenantId, AzureEnvironment



   var azure = Azure.Authenticate(cred).WithDefaultSubscription();

Unfortunately this code might fail with following error:

'this.Client.SubscriptionId' cannot be null

The reason for this is following code:

var azure = Azure.Authenticate(cred).WithDefaultSubscription();

This code is used in almost all Fluent API samples. But it works only (for now) if you have a default subscription. In the real life, you will most likely deal with multiple subscription. In this case will listed code fail, with named exception.

To workaround this error, you sill have to explicitly chose your subscription:

var azure = Azure.Authenticate(cred).WithSubscription(subscriptionId);

Posted Feb 14 2017, 06:14 PM by Damir Dobric
developers.de is a .Net Community Blog powered by daenet GmbH.