Question

I am using VSTO for Excel 2007 and managing excel application events using IConnectionPointContainer rather than subscribing them directly. Now prior to Office 2013, I wasn't using VSTO but implementing IExtensibility2 interface. I used to get excel application object directly and managing the excel events was done as below:

IConnectionPoint _eventSourceConnectionPoint;
ComObjLifetimeManager _eventSourceConnectionPointLifeManager;

var _eventSource = excelApplication as IConnectionPointContainer;
_eventSource.FindConnectionPoint(ref _xlAppEventsIID, out _eventSourceConnectionPoint);
_eventSourceConnectionPointLifeManager = new ComObjLifetimeManager(_eventSourceConnectionPoint);
_eventSourceConnectionPoint.Advise(this, out _connectionCookie);

This used to work perfectly fine previously. Now that I am using VSTO, I am getting TargetInvocationException exception on calling _eventSource.FindConnectionPoint() method.

"The interface does not support late bound calls since it does not derive from IDispatch"

All the things are same as previous except that I am now getting the excel application object from "this.Application" rather than getting it for free via IExtensibility2 interface.

Was it helpful?

Solution

Even after a lot of research I wasn't getting anywhere, then I accidentally landed here : http://blogs.msdn.com/b/vsod/archive/2010/04/07/how-to-implement-late-bound-event-handling-in-case-of-a-vsto-add-in.aspx
which solved my problem. For anyone else having the same problem, you basically need to do the following in assemblyinfo.cs:

1. Set ExcelLocale1033 attribute to false
2. Mark the assembly as COM Visible
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top