Skip to content

Remove and re-import broke the ALC, reimporting after restore - #3804

Merged
Ramses Sanchez-Hernandez (ramsessanchez) merged 1 commit into
microsoftgraph:mainfrom
svrooij:fix-reimport
Oct 1, 2026
Merged

Ramses Sanchez-Hernandez (ramsessanchez) merged 1 commit into
microsoftgraph:mainfrom
svrooij:fix-reimport

Conversation

@svrooij

@svrooij Stephan van Rooij (svrooij) commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Changes proposed in this pull request

  • The introduced ALC did not re-import after removal and importing the module (because the ALC stayed in the default context, and was not initialized again)
  • Added a test for this as well so there won't be a release with this regression again.

Reproduce the bug (thanks to Fabien Tschanz (@FabienTschanz) link):

PS> Import-Module Microsoft.Graph.Authentication
PS> Remove-Module Microsoft.Graph.Authentication
PS> Import-Module Microsoft.Graph.Authentication
$FileNotFoundException/   at 
...
System.Reflection.RuntimeAssembly.Microsoft.Graph.PowerShell.Authentication.Utilities.Runtime.Cmdlets.GetModuleCmdlet.ProcessRecord()
Get-ModuleCmdlet: Could not load file or assembly 'Microsoft.Graph.Authentication.Core, Version=2.41.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

@svrooij

Copy link
Copy Markdown
Contributor Author

Ramses Sanchez-Hernandez (@ramsessanchez) fellow MVPs were reporting issues that happend after removing and re-importing the released module. I did not test this exact use-case before.

@FabienTschanz

Copy link
Copy Markdown
Contributor

Repro scenario:

PS> Import-Module Microsoft.Graph.Authentication
PS> Remove-Module Microsoft.Graph.Authentication
PS> Import-Module Microsoft.Graph.Authentication
$FileNotFoundException/   at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|48_0(NativeAssemblyNameParts* __pAssemblyNameParts_native, ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, Int32 __throwOnFileNotFound_native, ObjectHandleOnStack __assemblyLoadContext_native, ObjectHandleOnStack __retAssembly_native)
   at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|48_0(NativeAssemblyNameParts* __pAssemblyNameParts_native, ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, Int32 __throwOnFileNotFound_native, ObjectHandleOnStack __assemblyLoadContext_native, ObjectHandleOnStack __retAssembly_native)
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
   at System.Reflection.TypeNameResolver.ResolveAssembly(AssemblyName assemblyName)
   at System.Reflection.TypeNameResolver.GetType(String escapedTypeName, ReadOnlySpan`1 nestedTypeNames, TypeName parsedName)
   at System.Reflection.TypeNameResolver.Resolve(TypeName typeName)
   at System.Reflection.TypeNameResolver.GetTypeHelper(Char* pTypeName, RuntimeAssembly requestingAssembly, Boolean throwOnError, Boolean requireAssemblyQualifiedName, IntPtr unsafeAccessorMethod)
   at System.Reflection.CustomAttribute.<CreateCustomAttributeInstance>g____PInvoke|30_0(QCallModule __pModule_native, ObjectHandleOnStack __type_native, ObjectHandleOnStack __pCtor_native, IntPtr* __ppBlob_native, IntPtr __pEndBlob_native, Int32* __pcNamedArgs_native, ObjectHandleOnStack __instance_native)
   at System.Reflection.CustomAttribute.CreateCustomAttributeInstance(RuntimeModule module, RuntimeType type, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
   at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
   at System.RuntimeType.GetCustomAttributes(Boolean inherit)
   at System.Management.Automation.CommandMetadata.ConstructCmdletMetadataUsingReflection()
   at System.Management.Automation.CommandMetadata.Init(String name, String fullyQualifiedName, Type commandType, Boolean shouldGenerateCommonParameters)
   at System.Management.Automation.CommandMetadata..ctor(CommandInfo commandInfo, Boolean shouldGenerateCommonParameters)
   at Microsoft.Graph.PowerShell.Authentication.Utilities.Runtime.Cmdlets.GetModuleCmdlet.<ProcessRecord>b__16_0(CommandInfo ci)
   at System.Linq.Enumerable.IEnumerableWhereIterator`1.ToArray()
   at Microsoft.Graph.PowerShell.Authentication.Utilities.Runtime.Cmdlets.GetModuleCmdlet.ProcessRecord()
Get-ModuleCmdlet: Could not load file or assembly 'Microsoft.Graph.Authentication.Core, Version=2.41.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

@ramsessanchez

Copy link
Copy Markdown
Contributor

testing in #3807, will merge and release a patch once build is successful

@ramsessanchez
Ramses Sanchez-Hernandez (ramsessanchez) merged commit bc69e67 into microsoftgraph:main Oct 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants