daxian-dbw / PowerShell-ALC-Samples

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

Update the sample to include the option to use `Assembly.LoadFile` #5

Closed daxian-dbw closed 2 years ago

daxian-dbw commented 2 years ago

Update the sample to include the option to use Assembly.LoadFile

The Assembly.LoadFile API uses an anonymous AssemblyLoadContext to load the assembly file. But it maintains a cache to guarantee that the same assembly instance is returned for the same assembly file path. For details, see the .NET code at https://source.dot.net/#System.Private.CoreLib/Assembly.cs,239.

So, it's OK to use Assembly.LoadFile as a simpler version of the same technique.