Application.GetActiveInstance throws exception "The object's type must be __ComObject..."

Apr 23, 2013 at 4:10 PM
On Windows 8 with office 2013,
var outlookApplication = Outlook.Application.GetActiveInstance();
throws the following exception:

The object's type must be __ComObject or derived from __ComObject.
Parameter name: o System.ArgumentException System.ArgumentException: The object's type must be __ComObject or derived from __ComObject.
Parameter name: o
at System.Runtime.InteropServices.Marshal.ReleaseComObject(Object o)
at NetOffice.RunningObjectTable.GetActiveProxyFromROT(String componentName, String className, Boolean throwOnError)
at NetOffice.OutlookApi.Application.GetActiveInstance()

Similar exception if thrown for other applications - Word, PowerPoint

The object's type must be __ComObject or derived from __ComObject.
Parameter name: o System.ArgumentException System.ArgumentException: The object's type must be __ComObject or derived from __ComObject.
Parameter name: o
at System.Runtime.InteropServices.Marshal.ReleaseComObject(Object o)
at NetOffice.RunningObjectTable.GetActiveProxiesFromROT(String componentName, String className)
at NetOffice.WordApi.Application.GetActiveInstances()


On Windows 7 with office 2013 the same application seems to work fine. UAC is disabled completely on Windows 7, and only partially on Windows 8.
Apr 24, 2013 at 5:07 PM
Edited Apr 24, 2013 at 5:07 PM
I tried to debug the problem. For some reason, during iteration over ROT , one of the components is not a COMObject , but is System.MarshalByRefObject.
   if (componentNameEqual && classNameEqual)
   {
                    Marshal.ReleaseComObject(bindInfo);
                    return comInstance;
   }
   else
   {
                    componentNameEqual = ((_ballmersPlace + componentName).Equals(component, StringComparison.InvariantCultureIgnoreCase));
                    if (componentNameEqual && classNameEqual)
                    {
                        Marshal.ReleaseComObject(bindInfo);
                        return comInstance;
                    }
                    else
                        Marshal.ReleaseComObject(comInstance); // <=== Exception thrown here
    }
May 8, 2013 at 2:47 PM
Today I had the same problem with Access 2010 application.

Checking the instance type before calling Marshal.ReleaseComObject would solve this issue.
if (comInstance.GetType().IsCOMObject)
    Marshal.ReleaseComObject(comInstance);
I created a new Issue for this problem, hoping it will be solved in the next release.

https://netoffice.codeplex.com/workitem/19683
Coordinator
May 9, 2013 at 9:35 PM
this is strange, no idea why the ROT instance doesnt support __ComObject.
i want change the implementation. thanks !!!
Sebastian
Nov 14, 2013 at 2:09 PM
Hello i have the same issue....

the problems ocurs on Windows 8 with UAC activated... office 2013, if UAC is desactivated, no error ocurr...
i'm using current stable version NetOffice 1.6.0

Outlook.Application outlookApplication = new Outlook.Application();

Ex:

System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NetOffice.COMObject.CreateFromProgId(String progId)
at NetOffice.COMObject..ctor(String progId)
at NetOffice.OutlookApi.Application..ctor()
at InvocePersonal.Actualizar.backgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in ... :line 59