Skip to content

Nullreferenceexception in az accounts#10292 #10303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
863699b
add getter for DefaultContext to throw exception when not login, this…
VeryEarly Oct 16, 2019
1851018
remove unused import
VeryEarly Oct 16, 2019
b046c9a
use DefaultContext instead of _profile.DefaultContext for ListTenants…
VeryEarly Oct 16, 2019
b075445
apply DefaultContext to replace all _profile.DefaultContext to avoid …
VeryEarly Oct 16, 2019
518f489
add getter for DefaultContext to avoid NullReferenceException for Get…
VeryEarly Oct 16, 2019
92f39ce
add getter for DefaultContext to avoid NullReferenceException for Set…
VeryEarly Oct 16, 2019
ee96257
update ChangeLog.md
VeryEarly Oct 16, 2019
5c88f7c
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
VeryEarly Oct 17, 2019
ac5839a
add debug
VeryEarly Oct 18, 2019
e9243c7
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
VeryEarly Oct 18, 2019
3c436cf
revert incorrect commit,remove debug
VeryEarly Oct 18, 2019
24851af
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
VeryEarly Oct 22, 2019
d16c94f
revert DefaultContext to _profile.DefaultContext to pass test cases e…
VeryEarly Oct 22, 2019
f1853c7
merge conflict
VeryEarly Oct 24, 2019
ada41d2
remove extra whitespaces
VeryEarly Oct 24, 2019
edea519
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
VeryEarly Oct 24, 2019
629d2ff
add getter for DefaultContext to throw exception when not login, this…
VeryEarly Oct 16, 2019
ab74bf2
remove unused import
VeryEarly Oct 16, 2019
5f726d8
use DefaultContext instead of _profile.DefaultContext for ListTenants…
VeryEarly Oct 16, 2019
b398e09
apply DefaultContext to replace all _profile.DefaultContext to avoid …
VeryEarly Oct 16, 2019
604dceb
add getter for DefaultContext to avoid NullReferenceException for Get…
VeryEarly Oct 16, 2019
938ab90
add getter for DefaultContext to avoid NullReferenceException for Set…
VeryEarly Oct 16, 2019
faf21e5
add debug
VeryEarly Oct 18, 2019
01d335c
revert incorrect commit,remove debug
VeryEarly Oct 18, 2019
a74bbea
revert DefaultContext to _profile.DefaultContext to pass test cases e…
VeryEarly Oct 22, 2019
c1a425c
remove extra whitespaces
VeryEarly Oct 24, 2019
cfa3cb3
Merge branch 'nullreferenceexception-in-AzAccounts#10292' of github.c…
VeryEarly Oct 25, 2019
9bdd5cb
Merge branch 'master' into nullreferenceexception-in-AzAccounts#10292
VeryEarly Jan 6, 2020
273f3b2
remove unused dependencies
VeryEarly Jan 6, 2020
0a43a41
remove override DefaultContext
VeryEarly Mar 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Fix Get-AzTenant/Get-AzDefault/Set-AzDefault throw NullReferenceException when not login

## Version 1.7.0
* Updated Add-AzEnvironment and Set-AzEnvironment to accept parameters AzureAttestationServiceEndpointResourceId and AzureAttestationServiceEndpointSuffix
Expand Down
2 changes: 1 addition & 1 deletion src/Accounts/Accounts/Default/ClearAzureRmDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void ExecuteCmdlet()
throw new Exception("Default Resource Group cannot be set on CloudShell");
}

IAzureContext context = AzureRmProfileProvider.Instance.Profile.DefaultContext;
IAzureContext context = DefaultContext;
// If no parameters are specified, clear all defaults
if (!ResourceGroup)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Accounts/Accounts/Default/GetAzureRmDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GetAzureRMDefaultCommand : AzureRMCmdlet

public override void ExecuteCmdlet()
{
IAzureContext context = AzureRmProfileProvider.Instance.Profile.DefaultContext;
IAzureContext context = DefaultContext;
IResourceManagementClient client = AzureSession.Instance.ClientFactory.CreateCustomArmClient<ResourceManagementClient>(
context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager),
AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(context, AzureEnvironment.Endpoint.ResourceManager),
Expand Down
2 changes: 1 addition & 1 deletion src/Accounts/Accounts/Default/SetAzureRMDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override void ExecuteCmdlet()
throw new Exception("Default Resource Group cannot be set on CloudShell");
}

IAzureContext context = AzureRmProfileProvider.Instance.Profile.DefaultContext;
IAzureContext context = DefaultContext;
IResourceManagementClient resourceManagementclient = AzureSession.Instance.ClientFactory.CreateCustomArmClient<ResourceManagementClient>(
context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager),
AzureSession.Instance.AuthenticationFactory.GetServiceClientCredentials(context, AzureEnvironment.Endpoint.ResourceManager),
Expand Down
14 changes: 13 additions & 1 deletion src/Accounts/Accounts/Models/RMProfileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public class RMProfileClient
private IAzureTokenCache _cache;
public Action<string> WarningLog;

private IAzureContext DefaultContext
{
get
{
if(_profile == null || _profile.DefaultContext == null || _profile.DefaultContext.Account == null)
{
throw new PSInvalidOperationException(ResourceMessages.RunConnectAccount);
}
return _profile.DefaultContext;
}
}

public RMProfileClient(IProfileOperations profile)
{
_profile = profile;
Expand Down Expand Up @@ -368,7 +380,7 @@ public List<AzureTenant> ListTenants(string tenant = "")
return new List<AzureTenant>() { CreateTenant(tenant) };
}

List<AzureTenant> tenants = ListAccountTenants(_profile.DefaultContext.Account, _profile.DefaultContext.Environment, null, ShowDialog.Never, null);
List<AzureTenant> tenants = ListAccountTenants(DefaultContext.Account, DefaultContext.Environment, null, ShowDialog.Never, null);
return tenants.Where(t => string.IsNullOrEmpty(tenant) ||
tenant.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase) ||
tenant.Equals(t.Directory, StringComparison.OrdinalIgnoreCase))
Expand Down