Use AssemblyLoadContextProxy instead of Assembly.LoadFile.
Do not use Assembly.LoadFile for the dependency isolation purpose.
This API does load an assembly to a separate AssemblyLoadContext instance, but assemblies loaded by this API are discoverable by PowerShell's type resolution code (see code here).
So, your module could run into the "Type Identity" issue when loading an assembly by Assembly.LoadFile while another module loads a different version of the same assembly into the default AssemblyLoadContext.
Use
AssemblyLoadContextProxy
instead ofAssembly.LoadFile
.Do not use
Assembly.LoadFile
for the dependency isolation purpose.This API does load an assembly to a separate
AssemblyLoadContext
instance, but assemblies loaded by this API are discoverable by PowerShell's type resolution code (see code here).So, your module could run into the "Type Identity" issue when loading an assembly by
Assembly.LoadFile
while another module loads a different version of the same assembly into the defaultAssemblyLoadContext
.