如何使用应用程序域在C#.net中执行程序集 [英] how to execute the assembly in C#.net using app domain

查看:91
本文介绍了如何使用应用程序域在C#.net中执行程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在执行应用程序域中的程序集时遇到问题

ClassLibrary1是程序集,而我仅包含一个方法TestMethod()

在此测试方法中,将访问网站"www.google.com"

如果我这样称呼它工作正常,但是我需要通过appdomain称呼它.
ClassLibrary1.Class1.TestMethod();

我的示例代码是:

Hi
I am getting a problem in executing the assembly in app domain

ClassLibrary1 is the assembly and i contains the only one method TestMethod()

In this Testmethod will access the website "www.google.com"

if i call like this its Working fine, but i need to call this through the appdomain.
ClassLibrary1.Class1.TestMethod();

my sample code is:

object[] hEvidence = {new Zone (System.Security.SecurityZone.Internet) };
     Evidence AppEvidence = new Evidence(hEvidence, null);
     AppDomain d = AppDomain.CreateDomain("ClassLibrary1domain");
     d.ExecuteAssemblyByName("ClassLibrary1", AppEvidence);
     AppDomain.Unload(d);



我在这里创建的Appdomian仅具有对Internet的访问权限
我遇到错误



Here i am creating the appdomian with only the privileges access to the Internet
i am getting the Error

Request for the permission of type ''System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'' failed.



这是什么问题,我要去哪里了.



What it is the problem, where i am going wrong.

推荐答案

您读过错误消息吗?很清楚问题出在哪里,辅助程序集中的某件东西正在请求UIPermission特权,并且不允许这样做.

WebRequest只需要WebPermission(根据其文档),所以我想您正在做您没有告诉我们的其他事情.例如,Console.WriteLine需要UIPermission,MessageBox.Show也需要UIPermission.
Did you read the error message? It is quite clear what the problem is, something in your secondary assembly is requesting the UIPermission privilege and it isn''t allowed to do it.

WebRequest only requires the WebPermission (according to its documentation), so I guess you are doing something else you haven''t told us. For example Console.WriteLine requires UIPermission, as does MessageBox.Show.


这篇关于如何使用应用程序域在C#.net中执行程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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