AssemblyLoadContext validates that the assembly returned from Load has the same name as the name which was asked for. This validation incorrectly handles dynamic assemblies and will always fail for them.
This is the cause because ValidateAssemblyNameWithSimpleName simply casts the returned assembly to RuntimeAssembly:
|
RuntimeAssembly? rtLoadedAssembly = assembly as RuntimeAssembly; |
But this doesn't work for assemblies created by AssemblyBuilder.
The code should call GetRuntimeAssembly instead, which handles this case correctly.
Full repro for both affected public APIs (Load and Resolving) is here:
https://gist.github.com/vitek-karas/3c8f938dc15730ad00a375d8d745f36a
This is basically a derivative issue from the bug fix in #49387.
AssemblyLoadContextvalidates that the assembly returned fromLoadhas the same name as the name which was asked for. This validation incorrectly handles dynamic assemblies and will always fail for them.This is the cause because
ValidateAssemblyNameWithSimpleNamesimply casts the returned assembly toRuntimeAssembly:runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
Line 660 in 01c9cf6
But this doesn't work for assemblies created by
AssemblyBuilder.The code should call
GetRuntimeAssemblyinstead, which handles this case correctly.Full repro for both affected public APIs (
LoadandResolving) is here:https://gist.github.com/vitek-karas/3c8f938dc15730ad00a375d8d745f36a
This is basically a derivative issue from the bug fix in #49387.