AppDomain Unload killing Parent AppDomain

时光毁灭记忆、已成空白 提交于 2019-11-30 19:19:21
IAbstract

As I suspected, instancing with the IModule interface in the primary domain causes a leak. In order to do this properly:

AppDomain domain = AppDomain.CreateDomain(domainName);
HostDomains[domainName] = domain;  // put in collection

ModuleAdapter adapter = (ModuleAdapter)domain.CreateInstanceAndUnwrap(asmName , typeName);

where ModuleAdapter inherits MarshalByRefObject. Then:

adapter.Execute(moduleAssembly , moduleType);

Inside the ModuleAdapter class:

public void Execute(string Name, string EntryPoint)
{
    module  = (IModule)AppDomain.CurrentDomain.CreateInstanceAndUnwrap(Name , EntryPoint);
}

I do welcome comments or additional answers for a better way.

After moving the instancing to the ModuleAdapter class, we are still having the issue with AppDomain.Unload killing the entire application. I was wondering if this is because in the module plugin we are using Application.Run(myForm) - then when we shutdown we call myForm.Close(). Obviously this shuts down the application so I was wondering if the myForm.Close() also 'unloads' the AppDomain.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!