MyAddIn not found in loaded LateBindingApi Assemblies Exception

Dec 20, 2011 at 12:14 PM
Edited Dec 20, 2011 at 12:17 PM

Hi,

I get a System.Exception when trying to access MyAddIn.Object:

Message:
class f3aaca24-47d5-4d10-a924-c33f903de7f0:AddInCommunication not found in loaded LateBindingApi Assemblies
Currently loaded LateBindingApi Assemblies
Loaded LateBindingApi Assembly:00062fff-0000-0000-c000-000000000046 OutlookApi, Version=1.3.0.2, Culture=neutral, PublicKeyToken=ab91c198d7b96dca
Loaded LateBindingApi Assembly:2df8d04c-5bfa-101b-bde5-00aa0044de52 OfficeApi, Version=1.3.0.2, Culture=neutral, PublicKeyToken=1208423a019d3443

Stack Trace:
   bei LateBindingApi.Core.Factory.CreateObjectFromComProxy(COMObject caller, Object comProxy)
   bei NetOffice.OfficeApi.COMAddIn.get_Object()

For better understanding I will paste some code snippets:

1. Solution "MyAddIn", build with VS2008, Template Outlook 2007 Add-In, Running in Outlook 2010. Build-Options: Register for COM interop: true. In AssemblyInfo.cs set ComVisible: true. The addin works as desired.

public partial class ThisAddIn
{
    private IAddInCommunication addInCommunication;

    protected override object RequestComAddInAutomationService()
    {
      if (addInCommunication == null)
      {
        addInCommunication = new AddInCommunication();
      }

      return addInCommunication;
    }
}

[ComVisibleAttribute(true)]
[ClassInterface(ClassInterfaceType.None)]
public class AddInCommunication : StandardOleMarshalObject, Outlook.IAddInCommunication
{
  public void Test()
  {
  }
}

2. Solution "Outlook", Class-Lib, Build-Options: Register for COM interop: true. In AssemblyInfo.cs set ComVisible: true

[ComVisibleAttribute(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IAddInCommunication
{
  void Test();
}

3. Solution "WinForms", trying to access AddInCommunication of MyAddIn running in Outlook 2010.:

public void Connect()
{
  LateBindingApi.Core.Factory.Initialize();
  var app = GetApplicationInstance();
  Application = app != null
                ? new Application(null, app)
                : new Application();

  var addin = Application.COMAddIns["MyNamespace.MyAddIn"];
  var comm = addin.Object as Outlook.IAddInCommunication; //this throws the exception
}

As I interpret the exception, NetOffice is looking in OutlookApi and OfficeApi for AddInCommunication.
This will cause the exception - the class exists in assembly MyAddIn. But here is maybe another problem: I will not work with the implentation (no reference between WinForms and MyAddIn!) of AddInCommunication. I need to use IAddInCommunication...

Doing this with normal Outlook COM access (not NetOffice) works as follow:

 object index = "MyNamespace.MyAddIn";
 var addin = Application.COMAddIns.Item(ref index);
 object obj = addin.Object; //while debugging type is System.__ComObject
 var xx = obj as IAddInCommunication;

So my question is: What are I am doing wrong?

Coordinator
Dec 20, 2011 at 12:32 PM
Edited Dec 20, 2011 at 12:32 PM

hello,

oh this is special scenario, NetOffice analyze the proxy and try to find an coresponding wrapper.
in this case we have no NetOffice wrapper class of course because the return value is not an office type.
please use the low-level invoker in this case:

object proxy = LateBindingApi.Core.Invoker.PropertyGet(addin, "Object");

 

as far i known the Object property is null by default, you have to set this property in your addin.

*regards
Sebastian

 

Dec 20, 2011 at 12:49 PM

works perfect! thank you so much!