daxian-dbw / PowerShell-ALC-Samples

Samples for solving PowerShell module assembly dependency conflicts using `AssemblyLoadContext`.
MIT License
16 stars 6 forks source link

Do not use Assembly.LoadFile for dependency isolation #12

Closed daxian-dbw closed 2 years ago

daxian-dbw commented 2 years ago

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.