System.InvalidCastException with outlook application

0

I use this code to access to our outlook DB and retrieve the logged in user:

Outlook.Application oApp = null;

if (System.Diagnostics.Process.GetProcessesByName("OUTLOOK").Count() > 0)
{
    oApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
}
else oApp = new Outlook.Application();                

Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon("Default Outlook Profile", "", false, true); // using the default outlook profile               

return oNS.CurrentUser.Name;

One of our colleague have a Windows 7 x64 version instead of normally installed 32 bit Windows and get following error: (other users don't have issues)

Error: Can't retrieve UserName from System!
System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at Microsoft.Office.Interop.Outlook.ApplicationClass.GetNamespace(String Type)

Which package or libraries are missing?

Thx

c#
windows
outlook
asked on Stack Overflow Oct 20, 2014 by leon22

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0