创建应用程序域并加载程序集 [英] Create application domain and load assembly

查看:98
本文介绍了创建应用程序域并加载程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个具有默认权限的应用程序域,并以默认权限将程序集加载到该应用程序域中,并在程序集中执行这些方法。

I want to create an application domain with default permissions and load assembly into the application domain with default privileges and execute the methods inside the assembly.

推荐答案

您可以看看以下文章在MSDN上。或者,如果您想在另一个AppDomain中构造某个类型的实例(假设此类型具有默认构造函数):

You may take a look at the following article on MSDN. Or if you want to construct an instance of some type inside another AppDomain (assuming this type has a default constructor):

var domain = AppDomain.CreateDomain("NewAppDomain");
var path = @"C:\work\SomeAssembly.dll";
var t = typeof(SomeType);
var instance = (SomeType)domain.CreateInstanceFromAndUnwrap(path, t.FullName);

使用此方法返回的 instance 变量有效在新创建的应用程序域上,您就可以对其进行操作了。

The instance variable returned with this method lives on your newly created application domain and you are ready to manipulate it.

这篇关于创建应用程序域并加载程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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