【问题标题】:EntryAssembly for MAF AddInMAF 插件的 EntryAssembly
【发布时间】:2011-12-29 23:24:33
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: c# appdomain strongname maf


    【解决方案1】:

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

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

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

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

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

    你为什么不改用GetExecutingAssembly

    【讨论】:

      猜你喜欢
      • 2012-05-18
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多