-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
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:
runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
Line 660 in 01c9cf6
| 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.