There is a very strange problem with the assembly link and a download problem that I encounter with my Outlook add-on. Here is the detail (long story :)):
I have an old Outlook addin written and built using .Net 1.1. The addon is downloaded using unmanaged pads to its own application domain. It works fine with .Net 2.0, even if 1.1 is not present on the user machine.
Addin uses the custom Outlook interconnect build created by VS 2003 against Outlook 2000, and after that the rebuild will be heavily named (like my addon).
In the addin project, I refer only to this custom interop assembly, not referring to official MS interop assemblies.
When this addin is used in an environment with Outlook 2007 and .Net 2.0, where the official MS interop assemblies are installed in the GAC, for some reason I can see that addin downloads and uses them.
In the code for the Connect class, I have a using directive:
using Outlook;
which is the namespace of my custom interop assembly.
In Connect ctor, I have these lines of code (added for testing purposes):
Assembly.LoadFrom(PATHTOMYASSEMBLY + "Interop.Outlook.dll"); Type type = typeof(Outlook.ApplicationClass); logger.Debug("Outlook.Application full type is: {0}", type.AssemblyQualifiedName);
It is output:
Full view of Outlook.Application: Outlook.ApplicationClass, Interop.Outlook, Version = 9.0.0.0, Culture = neutral, PublicKeyToken = 4cfbdc5349cf59d8
This is exactly what I expected.
The problem is that when OnConnection (object application, Extensibility.ext_ConnectMode connectMode, addInInst object, ref System.Array custom), I see in the log (I have a hook to the AssemblyLoad event of the current domain), which is also loaded by MS interop:
private void app_domain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) { Assembly loadedAssembly = args.LoadedAssembly; logger.Debug("Assembly {0} is loaded from: {1}", loadedAssembly.FullName, loadedAssembly.GlobalAssemblyCache ? "GAC" : loadedAssembly.Location); }
Output:
Montage Microsoft.Office.Interop.Outlook, Version = 12.0.0.0, Culture = Neutral, PublicKeyToken = 71e9bce111e9429c - downloaded from: GAC
My OnConnection method starts as follows:
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { Type type = application.GetType(); logger.Debug("OnConnection application object full type is: {0}", type.AssemblyQualifiedName); Outlook.Application applicationObject = (Outlook.Application)application;
It is output:
OnConnection application object type: Microsoft.Office.Interop.Outlook.ApplicationClass, Microsoft.Office.Interop.Outlook, Version = 12.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c
This is really strange, as you can see that on the next line I can successfully apply to Outlook.Application without any problems.
I checked with Reflector, and my assembly in no way refers to the Microsoft interop assembly. Same for my Interop.Outlook.dll.
So, does anyone know what is going on? What is the answer to these questions:
NOTE. I created a new addin, very simple, which does nothing, just loads. I could reproduce the problem, so really, does anyone know how the CLR decides what to do and where it comes from. In addition, there is another place in the GAC (registry ???), where is the connection between the COM object and the required interaction?