HRESULT 异常:0x80004004 (E_ABORT)

Exception from HRESULT: 0x80004004 (E_ABORT)

我正在使用 C# 开发 VSTO Outlook AddIn 项目,并尝试使用以下方法在 Outlook 中添加 DocumentItem -

    protected void CreateWordDocument(string strPhysicalFilePath, Outlook.Folder ParentFolder)
    {

        Outlook.DocumentItem objDocItem = null;
        Outlook.Attachment objAtt = null;

        try
        {


            objDocItem = ParentFolder.Items.Add("IPM.Document");
            objAtt = objDocItem.Attachments.Add(strPhysicalFilePath, );

            objDocItem.Subject = objAtt.FileName;

            string strFileType = Path.GetExtension(strPhysicalFilePath, );

            switch (strFileType)
            {
                case ".doc":
                case ".docx":
                    objDocItem.MessageClass = "IPM.Document.Word.Document.8"; break;
                case ".xls":
                case ".xlsx":
                    objDocItem.MessageClass = "IPM.Document.Excel.Sheet.8"; break;
                case ".pps":
                case ".ppt":
                case ".pptx":
                    objDocItem.MessageClass = "IPM.Document.PowerPoint.Show.8"; break;
                case ".txt":
                    objDocItem.MessageClass = "IPM.document.txtfile"; break;
            }

            objDocItem.Save();

        }
        catch (Exception ex)
        {
            ErrorLog.WriteError("ClassName", "CreateWordDocument()", ex.Message);               
        }
        finally
        {
            if (objDocItem != null) Marshal.ReleaseComObject(objDocItem);
            if (objAtt != null) Marshal.ReleaseComObject(objAtt);               
        }

    }

但在行中出现以下错误 " objDocItem = ParentFolder.Items.Add("IPM.Document"); "

Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)) in outlook.Items.Add() in VSTO Outlook Addin.

相同的代码在我的电脑上运行良好,但在另一台电脑上出现此错误。

Microsoft 目前不推荐也不支持来自任何无人值守、非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT)的 Microsoft Office 应用程序自动化服务),因为当 Office 在此环境中 运行 时,Office 可能表现出不稳定的行为 and/or 死锁。

如果您正在构建 运行 在服务器端上下文中的解决方案,您应该尝试使用已针对无人值守执行安全处理的组件。或者,您应该尝试找到至少允许 运行 客户端部分代码的替代方案。如果您从服务器端解决方案使用 Office 应用程序,该应用程序将缺少许多 运行 成功所必需的功能。此外,您将承担整体解决方案稳定性的风险。在 Considerations for server-side Automation of Office 文章中阅读更多相关信息。

我已找到解决方案 - 32 位或 64 位目标平台存在问题。我在那里遇到异常的机器安装了 64 位 Office,我的 outlook 添加设置是在 32 位平台上构建的。我已经使用 64 位目标平台重新编译并构建了 outlook 添加安装程序并安装在该机器上。现在一切正常。