Marshal.GetActiveObject throws exception from esri c# addin

0

I want my esri addin to look for and use an existing instance of excel. The code:

 Microsoft.Office.Interop.Excel.Application exApp = null;

   try

   {

      exApp =     (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");

   }

   catch (Exception err)

   {MessageBox.Show(err.ToString()); }

GetActiveObject throws an exception every time, it doesn't matter if excel is running or not: exception from marshal.getactiveobject

System.Runtime.InteropServices.COMException (0x800401E3); Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
at System.Runtime.InteropServices.Marshal.GetActiveObject( bla bla bla)

I wrote a little test app (windows app) to do this same thing, it works as expected. It returns a reference to the instance of excel if excel is running, otherwise it returns null. It never throws the exception. Why is the addin throwing an exception every time? Something about esri addins? (It's an addin to arcmap)

Been banging on this for days now, any help is appreciated. thanks!

c#
add-in
arcmap
asked on Stack Overflow May 21, 2014 by user3662350 • edited May 21, 2014 by Hamlet Hakobyan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0