Skip to content

Microsoft.Graph.Authentication fails after removal and re-import in the same PowerShell session #3805

Description

Describe the bug

After the dependency-isolation changes introduced in #3789 , removing and re-importing Microsoft.Graph.Authentication in the same PowerShell 7+ session can leave dependency resolution broken.

Actual Behavior

Re-import or subsequent command execution can fail when resolving Microsoft.Graph.Authentication.Core.

Root Cause

Removing the module calls GraphLoadContextInitializer.Shutdown(), which unregisters the default-context resolver but retains the non-collectible private load context.

On re-import, Initialize() returns immediately because that context already exists, leaving the resolver unregistered. The binary module’s static constructor also does not run again.

Proposed Fix

Track resolver registration separately from context creation. Reuse the existing private context and re-register the resolver on subsequent imports.

Add regression coverage for importing, removing, and re-importing the module within one PowerShell process, followed by command execution and load-context assertions.

Fixed by PR: #3804

Expected behavior

The module can be removed and re-imported successfully, and its commands continue working with dependencies loaded into the private assembly load context.

How to reproduce

Using a build containing #3789 (v2.41):

Import-Module Microsoft.Graph.Authentication
Remove-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Authentication

SDK Version

2.41.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions