During activation, what will be the search path for the add-in dependency dlls ?

Jan 27, 2012 at 5:58 PM

I'm loading each add-in in a separate process by using the following:

   AddInProcess addInProcess = new AddInProcess();

   addIn = token.Activate<IPlugIn>(addInProcess, AddInSecurityLevel.FullTrust);

If the addIn has some dependency dlls, I found that by the time I invoked .Activate, it will try to load the dependency dlls from GAC, is there anyway that I can instruct it to load from a private path ? No matter if i put the dependency dlls under the directory where the host is located or the pipeline directory or the add-in directory, it always tries to load it from GAC, if the assemblies are not installed in GAC, it will report an error saying "unable to locate assembly". Is this expected ? I would like it to locate the dependency dlls from the private path rather than in GAC.

Thanks,
Agnes 

Jan 30, 2012 at 5:05 PM

Hello Agnes,

You don't have to add the referenced DLLs in the GAC.

What I do is simply add a reference to my add-in project and then set "CopyLocal" to true on the reference properties.

Regards,

Panos

Jan 31, 2012 at 4:20 AM

Hi Panos,

I tried to add reference to the common dlls from the add-in project and set the "CopyLocal" to true, but it does not work.

I looked at the Assembly Binding Log Viewer and seems like it starts from the framework directory as AppBase, and only look for the .NET config files, AddInProcess.exe.Config & Machine.config without looking under any application configs, is this expected ?

*** Assembly Binder Log Entry  (1/31/2012 @ 12:13:33 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\AddInProcess.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = ABC.Common, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = AddInProcess.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\AddInProcess.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

Jan 31, 2012 at 10:23 AM

Do you reference this assembly from any other project in the pipeline?

By the way have you tried to Activate the add-in in the same AppDomain with the host?

Jan 31, 2012 at 10:26 AM

Under the pipeline, this is the only add-in that reference those dlls.

Activating the add-in in a different AppDomain is fine, just activating it under a different process gives me this issue that I must load the referenced assemblies under the GAC.

Thanks.

Mar 22, 2012 at 3:06 PM

Hello Agnes,

Did you find the solution to this problem? I'm curious because, since I'm currently working on a MAF based application, it would help to be prepared for things that can go wrong.

Panos

Mar 23, 2012 at 3:32 AM
Hi Panos,

Sorry that I have not really put much time in this since we talked last time, right now, my plugin is running under a new App Pool instead of a separate process.

From my last test, if i were to run the plugin under a separate process, the dependent dlls need to be deployed under GAC, otherwise, I would get the dlls not found error as soon as I started the process.

I plan to go back to this later, maybe I can create a test project and verify this and let you know.

If there is anything that you find, i would be grateful if you could share that with me.

Thanks Panos!
Agnes


From: [email removed]
To: [email removed]
Date: Thu, 22 Mar 2012 07:06:36 -0700
Subject: Re: During activation, what will be the search path for the add-in dependency dlls ? [clraddins:287660]

From: p_ronto
Hello Agnes,
Did you find the solution to this problem? I'm curious because, since I'm currently working on a MAF based application, it would help to be prepared for things that can go wrong.
Panos
Read the full discussion online.
To add a post to this discussion, reply to this email (clraddins@discussions.codeplex.com)
To start a new discussion for this project, email clraddins@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Mar 28, 2012 at 10:37 AM

Hello Agnes,

I made another test to recreate the problem you mention. I did the following:

1) All projects in the pipeline have the following setting: Target framework = .Net Framework 4, Platform Target = Any CPU.

2) The add-in project references an assembly that is not in the GAC. I set "Copy Local" to false. I set this to create a FileNotFoundException.

3) Activated an add-in in a new process with FullTrust security level.

The FileNotFoundException was thrown and in details, I checked the FusionLog property. The log entry is the following:

=== Pre-bind state information ===
LOG: User = panos
LOG: DisplayName = Quartz, Version=2.0.0.100, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4
 (Fully-specified)
LOG: Appbase = file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : Cpi.Platform.AddIn.Ocr.FineReader, Version=1.0.0.20018, Culture=neutral, PublicKeyToken=5470f4aca8377cb7.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Quartz, Version=2.0.0.100, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4
LOG: Attempting download of new URL file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug/Quartz.DLL.
LOG: Attempting download of new URL file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug/Quartz/Quartz.DLL.
LOG: Attempting download of new URL file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug/Quartz.EXE.
LOG: Attempting download of new URL file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug/Quartz/Quartz.EXE.
LOG: Attempting download of new URL file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug/Ocr/FineReader/Quartz.DLL.
LOG: Attempting download of new URL file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug/Ocr/FineReader/Quartz/Quartz.DLL.
LOG: Attempting download of new URL file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug/Ocr/FineReader/Quartz.EXE.
LOG: Attempting download of new URL file:///C:/dev/projects/Visual Studio 2010/Experiments/Scanner/output/Debug/Ocr/FineReader/Quartz/Quartz.EXE.

Notice that the AppBase is in the add-in folder. In your log entry, it was in c:\windows\blahblah.

I run the test in a Windows 7 x86 with VS2010 and in a Windows 7 x64 with VS2010 and in both case the AppBase was the same. This means that if I set Copy Local = true, the referenced assembly will be copied in the add-in folder and will be loaded correctly since it will be in the AppBase.

Also note that I get the same behaviour when I activate the add-in in a new AppDomain (created by MAF). Exactly the same thing. AppBase is the add-in's folder. If you created the AppDomain yourself, then you can set any ApplicationBase (in System.AppDomainSetup) you want. This is great if you want to share assemblies between your add-ins. You can even subscribe to the AppDomain.AssemblyResolve event that is triggered when an assembly cannot be resolved and load it from another directory. Unfortunately I haven't found a way to do this when for add-ins hosted in a new process.

I can't understand why in your case the AppBase is in c:\windows\fram.... Maybe you should try to experiment with the project settings. Or maybe do a test solution from scratch and follow the steps I mentioned above.

Regards,

Panos