在DotNet Core中,是否可能卸载动态加载的程序集?

10

在 .net Framework 中可以将程序集加载到单独的 AppDomain 中,然后卸载它。 在 .net Core 中,AppDomain 不再可用,取而代之的是 AssemblyLoadContext。 我可以按以下方式将程序集加载到 AssemblyLoadContext 中:

 var assembly = AssemblyLoadContext.Default.LoadFromStream(stream);
有没有什么方法可以卸载它?

https://dev59.com/yG025IYBdhLWcg3wChKb - Eamonn McEvoy
3
据我所了解,.NET Core 没有应用程序域。我不知道这是否可以在没有应用程序域的情况下完成。 - Paul Baxter
1个回答

10

请查看此链接 here

卸载API尚未完成。

namespace System.Runtime.Loader
{
    public class AssemblyLoadContext
    {
        // Allow to create an unloadable ALC. The default constructor
        // will call this method with false
        protected AssemblyLoadContext(bool unloadable);

        // Returns true if this ALC is collectible
        public bool Unloadable {get; }

        // Allows to explicitly unload an ALC. Once this method is called,
        // any call to LoadFromXXX method will throw an exception
        public void Unload();
    }
}

有一个与卸载API相关的未解决问题,该API已获批准,可能会在未来版本中发布,因为里程碑标记为“Future”。


1
从.NET Core 3.0开始支持:https://learn.microsoft.com/en-us/dotnet/standard/assembly/unloadability - EM0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接