dotnetcore / BootstrapBlazor

Bootstrap Blazor is an enterprise-level UI component library based on Bootstrap and Blazor.
https://www.blazor.zone
Apache License 2.0
2.55k stars 298 forks source link

bug(CacheManager): unable to dynamically load DLL multiple times #3280

Closed ArgoZhang closed 6 months ago

ArgoZhang commented 6 months ago

Is there an existing issue for this?

Describe the bug

unable to dynamically load DLL multiple times

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

bb-auto[bot] commented 6 months ago

@ArgoZhang Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project that illustrates the problem.

ArgoZhang commented 6 months ago

Repro code

private void Test()
{
    GetName();
    GetName();
}

private void GetName()
{
    try
    {
        var folder = @"Plugins\Test";
        //新建插件域,并注明可卸载
        assemblyLoadContext = new AssemblyLoadContext(folder, true);

        var assembly = GetAssembly(@"Plugins\Test\Test.dll", assemblyLoadContext);
        var driverType = assembly.GetTypes().FirstOrDefault(x => typeof(ITestClass).IsAssignableFrom(x));
        System.Console.WriteLine(driverType.GUID.ToString());

        var driver = (ITestClass)Activator.CreateInstance(driverType)!;
        var name = Utility.GetPropertyValue(driver, nameof(ITestClass.Name));
        System.Console.WriteLine(name);
        assemblyLoadContext.Unload();
    }
    catch (Exception ex)
    {
        System.Console.WriteLine(ex);
    }
}