C# - Loading .NET Assembly into Separate AppDomain So You Can Unload It [duplicate]

旧街凉风 提交于 2019-12-09 11:44:58

问题


Possible Duplicate:
Loading DLLs into a separate AppDomain

What is the proper way to load a .NET assembly into a separate AppDomain so you can have access to its Types/Classes but still be able to unload it (and reload it).

This is a tangent of this previous discussion: C# - Correct Way to Load Assembly, Find Class and Call Run() Method


回答1:


Basically, you just create the new AppDomain, and then call AppDomain.CreateInstanceAndUnwrap to create the type. Here's a simple CodeProject article about this process.

There are some tricks, here. You can't ever refer to the Type directly (this will load the type into your current AppDomain), and the objects should all derive from MarshallByRefObj. This will allow you to use the object "remotely", meaning keep it from loading into your AppDomain.



来源:https://stackoverflow.com/questions/1228554/c-sharp-loading-net-assembly-into-separate-appdomain-so-you-can-unload-it

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