Skip to content

Add AssemblyLoadContext.LoadFromStream overload to populate Location and CodeBase #12822

Description

@albahari

Currently, assemblies loaded via AssemblyLoadContext.LoadFromStream end up with a blank Location and a CodeBase of System.Private.CoreLib.dll.

This causes trouble when you load an assembly that includes code such as this:

GetExecutingAssembly().Location

If you don't own the library that you're loading, you can't factor out this code, so the library breaks and LoadFromStream is effectively useless.

Can we have a new overload which loads an assembly from a stream while populating these properties:

public Assembly LoadFromStream(Stream assembly, Stream assemblySymbols, string location, string codeBase)

My own scenario for using LoadFromStream is to load an assembly without locking it so that it can be updated. The alternative is to copy the assemblies to a temporary location (and re-copy it each time it's updated) which is clumsy and inefficient. The temporary location causes two other problems. First, the assembly in question may rely on non-binary resources in the same folder as itself (or subfolders) which are now gone. Second, it makes it hard to diagnose issues related to loading the right DLL from the right place, because the original load location is obfuscated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-AssemblyLoader-coreclronly use for closed issuesenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions