Caleb
Caleb

Reputation: 299

EntryAssembly for MAF AddIn

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.

Upvotes: 1

Views: 270

Answers (1)

Panos Rontogiannis
Panos Rontogiannis

Reputation: 4172

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:

The assembly that is the process executable in the default application domain, or the first executable that was executed by AppDomain.ExecuteAssembly

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?

Upvotes: 1

Related Questions