MAF 插件的 EntryAssembly
有没有办法设置 MAF 插件,以便 System.Reflection从外接程序的 AppDomain 内部调用时,.Assembly.GetEntryAssembly() 返回对外接程序主程序集的引用?
背景:为了满足我的项目的某些安全要求,我必须在单独的 AppDomain 中加载插件,并且当从插件的 AppDomain 内部调用时,必须将 GetEntryAssembly() 的结果设置为插件的(强命名)主程序集。我按照 MSDN MAF 演练。在我的测试用例中,如果程序集加载到单独的 AppDomain(或进程)中,则 GetEntryAssembly() 始终返回 null。
我注意到 GetEntryAssembly 文档说“当从非托管应用程序加载托管程序集时,GetEntryAssembly 方法不会返回任何内容”——这是否适用于跨 AppDomain 边界的 MAF 代理?
相关的程序集和可执行文件都有强名称。
Is there a way to setup MAF addins so that System.Reflection.Assembly.GetEntryAssembly() returns a reference to the addin's main assembly when called from inside the addin's AppDomain?
Background: to meet certain security requirements for my project, I must load addins in a separate AppDomain, and the result of GetEntryAssembly() must be set to the addin's (strongly named) main assembly when called from inside the addin's AppDomain. I've developed a test case following the pattern laid out in the MSDN MAF walkthrough. In my test case, GetEntryAssembly() always returns null if the assembly is loaded in a separate AppDomain (or process).
I notice the GetEntryAssembly documentation says "The GetEntryAssembly method can return Nothing when a managed assembly has been loaded from an unmanaged application"--does this apply to MAF's proxying across AppDomain boundaries?
The assemblies and executables in question all have strong names.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的。它确实返回Nothing(空)。
但请注意,在 System.Reflection.Assembly.GetEntryAssembly< /a>,“返回值”描述为:
AppDomain.ExecuteAssembly 用于执行 a 的 main 方法.NET 应用程序。在您的情况下,不会执行任何应用程序。正在做什么,已解释 此处。
返回 Nothing (null) 是有意义的,因为没有调用 ExecuteAssembly。
为什么不使用 GetExecutingAssembly 来代替?
You are right about this. It does return Nothing (null).
But note that in the System.Reflection.Assembly.GetEntryAssembly, the "Return Value" is described as:
AppDomain.ExecuteAssembly is used to execute the main method of a .NET application. In your case no application is executed. What is being done, is explained here.
It makes sense to return Nothing (null) because there was no call to ExecuteAssembly.
Why don't you use GetExecutingAssembly instead?