是否可以卸载在dotnet核心中动态加载的程序集?

ali*_*ian 6 c# .net-core

在.net框架中可以在单独的AppDomain中加载程序集然后卸载它.在.net核心AppDomain不可用,并由AssemblyLoadContext取代.我可以将程序集加载到AssemblyLoadContext,如下所示:

 var assembly = AssemblyLoadContext.Default.LoadFromStream(stream);
Run Code Online (Sandbox Code Playgroud)

有没有办法卸载它?

Sri*_*ram 7

在这里查看此链接

卸载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();
    }
}
Run Code Online (Sandbox Code Playgroud)

卸载api有一个未解决的问题,并且api已被批准可能在未来版本中发布,因为里程碑在Future标签下.