无法将“System.__ComObject”类型的 COM 对象强制转换为接口类型“Redemption.RDOAppointmentItem”

问题描述 投票:0回答:1

下面的代码在五台 PC 上运行良好,但在一台 PC 上失败。我使用相同的用户登录虚拟机,并且代码运行良好。它在 foreach 循环中失败,我在其中投射“RDOAppointmentItem item in calendar.Items”。

这是返回的异常:

无法将“System.__ComObject”类型的 COM 对象强制转换为接口类型“Redemption.RDOAppointmentItem”。此操作失败,因为对 IID 为“{4959BA11-F9D0-4E57-AA7E-125636EEE44A}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口 (0x80004002 (E_NOINTERFACE))。

我是否未能针对此用户机器特定问题在我的代码中进行转换或解释某些内容?

RDOSession session = null;
RDOFolder calendar = null
 try
 {
    session = new RDOSession();
    session.Logon(System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, true, System.Reflection.Missing.Value, false);

    calendar = session.GetDefaultFolder(rdoDefaultFolders.olFolderCalendar);
 
    foreach (RDOAppointmentItem item in calendar.Items)
    { //do stuff}
outlook-redemption
1个回答
0
投票

理论上,日历文件夹中可以包含约会以外的项目。我有几个类似的幽灵物品 - 不知道它们来自哪里。 您可能想动态检查类型:

foreach (RDOMail entry in calendar.Items)
{
   if (entry is RDOAppointmentItem item)
   {
       //do stuff
   } 
}
© www.soinside.com 2019 - 2024. All rights reserved.