Skip to content

All AssemblyLoadContexts share a file path cache #112911

Open
@RomanSoloweow

Description

@RomanSoloweow

Description

Hi, my application has a plugin architecture and runs on Linux.

I've encountered an issue under the following scenario:

  1. Create a new assembly load context: new MyAssemblyLoadContext()
  2. Load an assembly: LoadFromAssemblyPath("my.dll")
  3. Install a new package
  4. Unload() - though it should not matter as contexts are supposed to be independent
  5. Create a new assembly load context: new MyAssemblyLoadContext()
  6. Load the same assembly again: LoadFromAssemblyPath("my.dll")

The LoadFromAssemblyPath method returns the old version of the assembly, even though the new version is already present on disk.

My context:

internal sealed class PluginLoadContext : AssemblyLoadContext
{
    private readonly AssemblyDependencyResolver _resolver;
 
    public PluginLoadContext(string name, assemblyPath)
        : base(isCollectible: true, name: name)
    {
        _resolver = new AssemblyDependencyResolver(assemblyPath);
    }
 
    protected override Assembly? Load(AssemblyName assemblyName)
    {
        var assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
        var assembly = assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null;
        return assembly;
    }
}

Reproduction Steps

  1. Create a new assembly load context: new MyAssemblyLoadContext()
  2. Load an assembly: LoadFromAssemblyPath("my.dll")
  3. Install a new package
  4. Unload() - though it should not matter as contexts are supposed to be independent
  5. Create a new assembly load context: new MyAssemblyLoadContext()
  6. Load the same assembly again: LoadFromAssemblyPath("my.dll")

Expected behavior

A new Assembly from the current dll will be loaded

Actual behavior

Returns Assembly loaded by another context

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions