1

有没有办法设置 MAF 插件,以便System.Reflection.Assembly.GetEntryAssembly()从插件的 AppDomain 内部调用时返回对插件主程序集的引用?

背景:为了满足我的项目的某些安全要求,我必须在单独的 AppDomain 中加载插件,并且从插件的 AppDomain 内部调用时,GetEntryAssembly() 的结果必须设置为插件的(强命名)主程序集。我按照MSDN MAF walkthrough中列出的模式开发了一个测试用例。在我的测试用例中,如果程序集加载到单独的 AppDomain(或进程)中,GetEntryAssembly() 始终返回 null。

我注意到 GetEntryAssembly 文档说“当从非托管应用程序加载托管程序集时,GetEntryAssembly 方法可以返回 Nothing”——这是否适用于 MAF 跨 AppDomain 边界的代理?

有问题的程序集和可执行文件都有强名称。

4

1 回答 1

1

你是对的。它确实返回 Nothing (null)。

但请注意,在System.Reflection.Assembly.GetEntryAssembly中,“返回值”描述为:

作为默认应用程序域中的进程可执行文件的程序集,或由 AppDomain.ExecuteAssembly 执行的第一个可执行文件

AppDomain.ExecuteAssembly用于执行 .NET 应用程序的主要方法。在您的情况下,没有执行任何应用程序。正在做什么,在这里解释。

返回 Nothing (null) 是有意义的,因为没有调用 ExecuteAssembly。

你为什么不使用GetExecutingAssembly呢?

于 2012-04-09T16:46:36.697 回答