在 .net 框架中,可以在单独的 AppDomain 中加载一个程序集,然后将其卸载。 在 .net 核心 AppDomain 中不可用并由 AssemblyLoadContext 取代。 我可以将程序集加载到 AssemblyLoadContext,如下所示:
var assembly = AssemblyLoadContext.Default.LoadFromStream(stream);
有什么办法可以卸载吗?
最佳答案
查看此链接 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 有一个 Unresolved 问题,该 api 已获得批准,可能会在未来版本中发布,因为里程碑位于 Future 标签下。
关于c# - 是否可以卸载在 dotnet 核心中动态加载的程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43106917/