This project has moved and is read-only. For the latest updates, please go here.

LateBindingApiException in OnConnection method

Apr 13, 2012 at 9:52 AM


my AddIn always crashes at this line in the IDTExtensibility2.OnConnection method:
_application = Factory.CreateObjectFromComProxy(null, Application);

and throws this Error:

LateBindingApi.Core.LateBindingApiException: Please call LateBindingApi.Core.Factory.Initialize() at LateBindingApi.Core.Factory.CreateObjectFromComProxy(COMObject caller, Object comProxy) at TestAddin1.Addin.Extensibility.IDTExtensibility2.InConnection(Object Application, ext_ConnectMode ConnectMode, Object AddInInst, Array&custom) in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\TestAddin1\TestAddin1\Addin.cs:line 41


LateBindingApi.Core.Factory.Initialize() is called in the constructor, so why do I get this Exception? Would really appreciate your help!




Apr 13, 2012 at 1:18 PM
Edited Apr 14, 2012 at 2:47 AM

are you sure the call is passed?
which NetOffice assemblies is referenced?
can you use the NetOffice debug console and copy the content here?


Mar 13, 2013 at 4:29 PM

I have the same problem my AddIn crashes on second line of the OnConnection method:
using Office2 = Microsoft.Office.Core;
using Extensibility;
using NetOffice;
// using Office = NetOffice.OfficeApi;
// using NetOffice.OfficeApi.Enums;
using Word = NetOffice.WordApi;
using NetOffice.WordApi.Enums;

public class Connect : Object, Extensibility.IDTExtensibility2, Office2.IRibbonExtensibility
    public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        COMObject app = Factory.CreateObjectFromComProxy(null, application);
runtime exception that I copied from VS output:
"A first chance exception of type 'NetOffice.LateBindingApiException' occurred in NetOffice.dll"

I use Microsoft.Office.Core because of that exception.
Your sample console application works on the same machine.
Windows Server 2008 R2
Microsoft Office 2010 64bit
Visual Studio 2010
.Net 3.5
Mar 13, 2013 at 4:41 PM

you want an addin for serveral office products right?
the problem is (i guess) you dont use a specific netoffice type in your code. the CLR doesnt load the referenced assembly in this case.
the factory method analyze the current loaded assemblies in the application domain and bazinga! nothing found in this case.
did you try the latest source state assemblies? (i create a better handling for non-loaded assemblies here) another way is to create a dumy method(never called) with Excel.Application exApp =null; Word.Application wdApp=null; to avoid the CLR optimization.

Mar 14, 2013 at 10:24 AM
I have added three private fields for Excel, Word and PowerPoint applications as you recommended me
and it works now!