Outlook VSTO - 在尝试通过 PropertyAccessor 获取 属性 之前测试 属性 是否存在

Outlook VSTO - testing whether a property exists, prior to attempting to get the property through the PropertyAccessor

在尝试通过 PropertyAccessor 获取 属性 之前,是否有测试 属性 是否存在的方法?

我使用下面的函数,使用 Outlook PropertyAccessor,return 属性 的字符串值。如果 属性 不存在,该函数会捕获错误并且 return 是一个空值字符串。我使用 debug.writeline 方法写出错误以明显地识别抛出的错误 - 我真正遇到的唯一错误是 Exception thrown: 'System.Runtime.InteropServices.COMException 和这通常与 属性 未知或无法找到有关。正在传递的 DASL 和 属性 名称是正确的并且有效 - 但并非所有电子邮件都具有这些属性 - 它们是由独立软件供应商创建的。

    ...
    using Outlook = Microsoft.Office.Interop.Outlook;
    ...
    private string GetPropertyString(Outlook.PropertyAccessor pa, string property)
    {
        string retVal = null;

        try
        {
            retVal = (string)pa.GetProperty(property);
        }
        catch (Exception ex)
        {
            retVal = null;
            Debug.WriteLine("OutlookProperties - GetPropertyString() - Error:=" + ex.Message);
            //throw;
        }
        finally
        {

        }
        return retVal;
    }

当 属性 不存在时,会抛出一个异常,当它被捕获时,它似乎没有被(正确)处理 - 输出是:

Exception thrown: 'System.Runtime.InteropServices.COMException' in Office777.dll

OutlookProperties - GetPropertyString() - Error:=The property "http://schemas.microsoft.com/mapi/string/{41FFBD02-4241-4EBD-A7B3-93DD2DF86CA9}/CaseGUID" is unknown or cannot be found.

非常感谢

处理异常是唯一的方法 - 旧版本的 Outlook 用于 return null,但最新版本总是抛出异常。检查 COMException.ErrorCode 也无济于事:它通常是 0x80020009 (DISP_E_EXCEPTION) 而不是更具信息性的内容,例如 MAPI_E_NOT_FOUND.