Skip to content

Commit 9ff2b42

Browse files
authored
Merge pull request #2842 from microsoftgraph/2795-when-using-in-azurechinacloud-environment-find-mggraphpermission-changes-msgraph-api-endpoints-from-china-to-global
Resets graph environment session to its original state.
2 parents 8ceb1db + 815b63f commit 9ff2b42

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,11 @@ private string QualifyFilePath(string path)
999999
/// </summary>
10001000
private void ResetGraphSessionEnvironment()
10011001
{
1002-
_originalEnvironment = GraphSession.Instance.Environment;
1003-
GraphSession.Instance.Environment = _originalEnvironment;
1002+
var currentEnvironment = GraphSession.Instance.Environment;
1003+
if(currentEnvironment != null && !currentEnvironment.Equals(_originalEnvironment))
1004+
{
1005+
GraphSession.Instance.Environment = _originalEnvironment;
1006+
}
10041007
}
10051008

10061009
#region CmdLet LifeCycle
@@ -1039,6 +1042,8 @@ private async Task ProcessRecordAsync()
10391042
if (ShouldCheckHttpStatus && !isSuccess)
10401043
{
10411044
var httpErrorRecord = await GenerateHttpErrorRecordAsync(httpResponseMessageFormatter, httpRequestMessage);
1045+
// A reset of the GraphSession Environment is required to avoid side effects
1046+
ResetGraphSessionEnvironment();
10421047
ThrowTerminatingError(httpErrorRecord);
10431048
}
10441049
await ProcessResponseAsync(httpResponseMessage);

0 commit comments

Comments
 (0)