.NET/Outlook互操作和保存附件:一个神秘的例外 [英] .NET / Outlook interop and saving attachments: a mysterious exception

查看:60
本文介绍了.NET/Outlook互操作和保存附件:一个神秘的例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自.NET新手的有关.NET/Outlook互操作的问题.我正在使用C#和MS Visual Studio 2008,MS Outlook 2003和Xobni(不确定是否相关).

异常详细信息和代码如下.


未处理System.InvalidCastException

Message ="无法将类型为'System .__ ComObject'的COM对象转换为接口类型'Microsoft.Office.Interop.Outlook .MailItem".此操作失败,因为具有以下错误的IID为"{00063034-0000-0000-C000-000000000046}"的COM组件上的COM组件上的QueryInterface调用由于以下错误而失败:不支持此类接口(HRESULT的异常:0x80004002(E_NOINTERFACE)) ."

源=" OLInteropTest"

StackTrace:

at OLInteropTest.Program.Main(String [] args)in t:\ Models \ psinis \ OReillyExamples \ OLInteropTest \ OLInteropTest \ Program.cs:line 20

System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args) 中的

,位于System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)

在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)

位于System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态)

在System.Threading.ThreadHelper.ThreadStart()

InnerException:

解决方案

有关与Office应用程序(如Outlook)自动化相关的问题和讨论,请参阅

Greetings,

 

This is a question about the .NET / Outlook interop, from a .NET novice. I’m using C# and MS Visual Studio 2008, MS Outlook 2003 and Xobni (not sure if that’s relevant).

The code goes into my inbox, iterates over each message, and saves all attachments to a directory. Each time I run the code, it successfully saves approx 30 attachments but then throws an exception which I don’t understand. Could anyone please shed some light on this? 

Exception details and code are below.


System.InvalidCastException was unhandled

  Message="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))."

  Source="OLInteropTest"

  StackTrace:

       at OLInteropTest.Program.Main(String[] args) in t:\Models\psinis\OReillyExamples\OLInteropTest\OLInteropTest\Program.cs:line 20

       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException:

For questions and discussions relating to automating Office applications (like Outlook) please see http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.officedev&lang=en&cr=US


这篇关于.NET/Outlook互操作和保存附件:一个神秘的例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆