在C#net中使用两个名称调用程序集 [英] Call the assembly with two name in C#net

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

问题描述


任何人都可以清楚地解释这一点吗?

我已经创建了名称为(ClassLibrary1.dll)的程序集,并创建并指定了Strong名称,到目前为止一切都很完美,

其实我的要求是
(1)创建一个程序集(testassembly1),该程序集可访问网页www.google.com
(2)为testassembly1创建一个强名称.
(3)创建一个应用程序域(具有默认权限)
(4)使用默认特权将testassembly1加载到应用程序域中. (5)加载另一个testassembly1实例(使用其他名称?).假设我们将其称为testassembly2,没有访问Internet或Intranet的特权.
(6)显示testassembly1和testassembly2的强名称的不同组成部分.
(7)在访问网页之前,请在您的代码中要求具有Internet和Intranet访问权限.如果异常,请打印错误.


问题到了5点,有人可以帮我吗

在此先感谢.

Hi
Can anybody explain this point clearly

i had created the assembly with the name as (ClassLibrary1.dll), i had created and assigned the Strong name,everthing is perfect upto now,

actually my requirement is
(1) Create one assembly (testassembly1) that accesses a web page www.google.com
(2) Create a strong name for testassembly1.
(3) Create an application domain (with default permissions)
(4) Load testassembly1 into the application domain with default privileges.
(5) Load another instance of testassembly1 (under different name?). Say we call it testassembly2 with no privileges to access internet or intranet.
(6) Display the different components of the strong name of testassembly1 and testassembly2.
(7) Before accessing the webpage, in your code, demand the permissions for internet and intranet access. If exception, print an error.


problem arrised at 5th point , can anybody help me please

Thanks in Advance.

推荐答案

我认为两次加载同一程序集(在同一Application Domain中)是不可能的,而且没有任何意义.最肯定的是,您可以使用相同的名称将相同的程序集加载到两个不同的应用程序域中,但这不是您要的.我不确定它是否也有意义,但是从技术上讲您应该可以做到.

加载部件时,没有其他名称".程序集具有很强的名称,这很好.您可以将其放入CAG中,以使其与众不同.

现在,您可以使用System.Reflection.Assembly.LoadFrom加载此程序集,其中此方法的参数必须是该程序集的主要可执行模块的文件名.名称是程序集来自程序集本身,而不是更改的主题.

如果在GAC中放置了相同的程序集,则可以使用方法System.Reflection.Assembly.Load并使用该程序集的全名对其进行标识.同样,此名称应完全相同,否则.NET将无法正确识别要加载的内容.

请参阅:
http://msdn.microsoft.com/en-us/library/1009fa28.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/x4cw969y.aspx [ ^ ].
请参阅其他加载方法: http://msdn.microsoft.com/en-us/library /system.reflection.assembly.aspx [ ^ ].

在我看来,两次加载同一个程序集的问题看起来像是:所有程序集类型的标识是由程序集的全名加上程序集内该类型的全限定名来定义的(这是不同的程序集如何携带名称相同的不同类型的方式) ).如果您可以两次加载同一程序集,则会破坏类型标识的唯一性.您将如何处理?

—SA
I think that loading the same assembly twice (in the same Application Domain) is not possible and cannot make any sense. Most certainly, you can load the same assembly in two different Application Domains under the same name, but this is not what you''re asking about. I''m not sure if it can make any sense, too, but technically you should be able to do so.

When you load an assembly, there is no "different name". The assembly has a strong name, this is good. You can put it in the CAG which makes it unique.

Now, you can load this assembly using the System.Reflection.Assembly.LoadFrom, where the argument of this method must be a file name of the main executable module of the assembly. The name is the assembly is taken from the assembly itself and is not a subject of the change.

If the same assembly is put in GAC, you can use the method System.Reflection.Assembly.Load and use a full name of the assembly to identify it. Again, this should be exact same name, otherwise .NET will not correctly identify what to load.

Please see:
http://msdn.microsoft.com/en-us/library/1009fa28.aspx[^],
http://msdn.microsoft.com/en-us/library/x4cw969y.aspx[^].
See other load methods: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^].

The problem of loading the same assembly twice looks to me like this: identity of all assembly types is defined by the full name of the assembly plus fully qualified name of the type within assembly (this is how different assemblies can carry different types with identical names). If you could load the same assembly twice you would break the uniqueness of the type identities. How would you deal with that?

—SA


这篇关于在C#net中使用两个名称调用程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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