问题
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