/// <summary> /// Gets the default subscription. /// </summary> /// <returns> Resource operations of the Subscription. </returns> #pragma warning disable AZC0015 // Unexpected client method return type. public virtual async Task <Subscription> GetDefaultSubscriptionAsync(CancellationToken cancellationToken = default) #pragma warning restore AZC0015 // Unexpected client method return type. { using var scope = new ClientDiagnostics(ClientOptions).CreateScope("ArmClient.GetDefaultSubscription"); scope.Start(); try { if (_defaultSubscription == null) { _defaultSubscription = await GetSubscriptions().GetAllAsync(cancellationToken).FirstOrDefaultAsync(_ => true, cancellationToken).ConfigureAwait(false); } else if (_defaultSubscription.HasData) { return(_defaultSubscription); } else { _defaultSubscription = await _defaultSubscription.GetAsync(cancellationToken).ConfigureAwait(false); } if (_defaultSubscription is null) { throw new InvalidOperationException("No subscriptions found for the given credentials"); } return(_defaultSubscription); } catch (Exception e) { scope.Failed(e); throw; } }