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

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

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

我使用Outlook PropertyAccessor利用下面的函数来返回属性的字符串值。如果该属性不存在,该函数将捕获错误并返回一个空值字符串。我使用debug.writeline方法写出错误以明显识别出抛出了什么错误-我真正遇到的唯一错误是Exception throwing:'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;
    }

[当属性不存在时,将引发异常,并且在捕获该异常的同时,似乎并没有(正确)处理该异常-输出为:

引发的异常:Office777.dll中的'System.Runtime.InteropServices.COMException']

OutlookProperties-GetPropertyString()-错误:=属性“http://schemas.microsoft.com/mapi/string/{41FFBD02-4241-4EBD-A7B3-93DD2DF86CA9} / CaseGUID”未知或找不到。

非常感谢

在尝试通过PropertyAccessor获取属性之前,是否有一种方法可以测试该属性是否存在?我使用Outlook PropertyAccessor,使用以下功能来...

c# outlook vsto
1个回答
0
投票

处理异常是唯一的方法-旧版本的Outlook用于返回null,但最新版本始终会引发异常。检查COMException.ErrorCode也无济于事:它通常是0x80020009(DISP_E_EXCEPTION),而不是更有意义的内容,例如MAPI_E_NOT_FOUND

© www.soinside.com 2019 - 2024. All rights reserved.