带有outlook应用程序的System.InvalidCastException

时间:2014-10-20 07:28:17

标签: c# windows outlook

我使用此代码访问Outlook数据库并检索登录用户:

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;

我们的一位同事拥有Windows 7 x64版本,而不是正常安装的32位Windows,并出现以下错误:(其他用户没有问题)

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)

缺少哪些软件包?

THX

0 个答案:

没有答案