C# - 加载.NET程序集到单独的AppDomain中,因此您可以卸载它 [英] C# - Loading .NET Assembly into Separate AppDomain So You Can Unload It

查看:199
本文介绍了C# - 加载.NET程序集到单独的AppDomain中,因此您可以卸载它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  加载DLL到一个单独的AppDomain

什么是正确的方式来加载.NET程序集到一个单独的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).

这是这个previous讨论的切线: <一href="http://stackoverflow.com/questions/1137781/c-correct-way-to-load-assembly-find-class-and-call-run-method">C# - 正确的方式来加载大会,查找类并调用run()方法

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

推荐答案

基本上,你只需要创建一个新的AppDomain,然后调用的 AppDomain.CreateInstanceAndUnwrap 以创建类型。关于这下面是一个简单的 $ C $的CProject文章流程。

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.

有一些技巧,在这里。你永远不能引用类型直接(这将加载类到当前的AppDomain),以及对象应的 MarshallByRefObj 。这将允许您使用对象的远程,意思是保持它加载到您的AppDomain。

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.

这篇关于C# - 加载.NET程序集到单独的AppDomain中,因此您可以卸载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆