I am creating an Excel add-in. Please note project type is Shared Add-in
vice Excel Workbook. In the OnStartupComplete event handler I am adding a
new menu item. I start by getting a reference to the Tools menu. This
works fine.
Type applicationType = applicationObject.GetType();
CommandBars bars = (CommandBars)applicationType.InvokeMember(
"CommandBars", BindingFlags.GetProperty, null, applicationObject,
null);
CommandBar bar = bars["Tools"];
Debug.WriteLine(bar.Name);
But the following more readable code throws "An unhandled exception of type
'System.ExecutionEngineException' occurred in testaddin.dll" on the third
line.
Excel.Application app = (Excel.Application)applicationObject;
CommandBars bars = app.CommandBars;
CommandBar bar = bars["Tools"];
Debug.WriteLine(bar.Name);
I have read Programming Office Applications Using Microsoft Visual C#
(http://msdn.microsoft.com/library/de.../OffCSharp.asp)
and the potential problem I see is "Handling Parameterized Properties with
Excel". But that doesn't seem applicable or the first version wouldn't work
correctly. What gives?