Skip to content

AssemblyLoadContext incorrectly validates name of dynamic assembly when returned from Load #53181

@vitek-karas

Description

@vitek-karas

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions