出现Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem' 错误的解决

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).


************** Exception Text **************
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at OutlookAddin1.ThisApplication.start() in C:"Documents and Settings"quigley-1"Desktop"OutlookAddin1"OutlookAddin1"ThisApplication.vb:line 70
   at OutlookAddin1.ThisApplication.ThisApplication_Startup(Object sender, EventArgs e) in C:"Documents and Settings"quigley-1"Desktop"OutlookAddin1"OutlookAddin1"ThisApplication.vb:line 7
   at Microsoft.Office.Tools.Outlook.Application.OnStartup()
   at OutlookAddin1.ThisApplication.FinishInitialization() in C:"Documents and Settings"quigley-1"Desktop"OutlookAddin1"OutlookAddin1"ThisApplication.Designer.vb:line 60
   at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecutePhase(String methodName)
   at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomizationStartupCode()
   at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomization(IHostServiceProvider serviceProvider)


************** Loaded Assemblies **************

 ===============================================

十有八九是 foreach 的时候 folder 里面 类型不统一

 

For Each MItem In MAPIFromFolder.Items ,You said "'it has never happened on the same email" so Please verify that in your MAPIFromFolder All the items should be Outlook.MailItem if not ,this error occurs.

Please add a check when your loop the folder.Do not use For Each.

 

 类似情况:

http://www.xtremevbtalk.com/archive/index.php/t-259552.html

详细原理

http://edndoc.esri.com/arcobjects/9.1/default.asp?url=/arcobjects/9.1/ArcGISDevHelp/DevelopmentEnvs/DotNet/SystemComObject.htm

posted on 2008-07-24 11:32  逝去的时光  阅读(6690)  评论(0)    收藏  举报

导航