Skip to content

Commit

Permalink
Fix exception in PnPConnectedCmdlet (#3885)
Browse files Browse the repository at this point in the history
Fix an NullDereferenceException happening when an exception is logged in PnPConnectedCmdlet but the connection passed through -Connection parameter is not the latest one.

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
jackpoz and gautamdsheth authored Apr 11, 2024
1 parent 8594f72 commit dd740d8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Commands/Base/PnPConnectedCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ protected override void ProcessRecord()
throw new PSInvalidOperationException(errorMessage);
}

Connection.RestoreCachedContext(Connection.Url);
if (Connection.Context.Url != Connection.Url)
{
Connection.RestoreCachedContext(Connection.Url);
}

// With ErrorAction:Ignore, the $Error variable should not be populated with the error, otherwise it should
if (!ParameterSpecified("ErrorAction") || !(new[] { "ignore" }.Contains(MyInvocation.BoundParameters["ErrorAction"].ToString().ToLowerInvariant())))
Expand Down

0 comments on commit dd740d8

Please sign in to comment.