ms 您所在的位置:网站首页 笔记本显示被调用对象与客户断开连接 ms

ms

2024-06-28 14:04| 来源: 网络整理| 查看: 265

我有一个用 C# 编写的程序,它通过整理一堆文本(从对象中提取)来创建一个 Word 文档。在过去的 4 年中,此应用程序在许多不同的机器上运行良好,但现在它正在为一个新客户端中断,并出现以下错误:

System.Runtime.InteropServices.COMException (0x80010108):调用的对象已与其客户端断开连接。(来自 HRESULT 的异常:0x80010108 (RPC_E_DISCONNECTED))在 Microsoft.Office.Interop.Word.DocumentClass.get_Content() 在 MyCompany.MyApp.Main.btnPrint_Click(Object sender, EventArgs e) 在 System.Windows.Forms.Control.OnClick( EventArgs e) 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs 事件) 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 点击) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ButtonBase.WndProc(Message& m) 在 System.Windows.Forms.Button.WndProc(Message& m) 在 System.Windows.Forms。 Control.ControlNativeWindow.OnMessage(消息&

这是代码片段(它不会按原样编译,因为这只是一个摘录,但应该有意义):

// This will be the collated doc object missing = System.Type.Missing; Document combinedDoc = null; // Temp doc holders string tempWordFilePath; object tempWordFilePathObj; // Loop thru records and add their content to Word doc foreach (RecordWrapper rec in records) { // Decode base64 attachment to byte-array byte[] b = decodeToBase64(rec.body); if (combinedDoc == null) combinedDoc = app.Documents.Add(ref missing, ref missing, ref missing, ref missing); tempWordFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + (string)o.Item("Name").Value; tempWordFilePathObj = tempWordFilePath; if (File.Exists(tempWordFilePath)) { File.Delete(tempWordFilePath); } // Write bytes into a temp Word doc FileStream fs = new FileStream(tempWordFilePath, FileMode.CreateNew); fs.Write(b, 0, b.Length); fs.Close(); // Load the temp file as a Document Document doc = app.Documents.Open(ref tempWordFilePathObj, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); // Insert page break object collStart = combinedDoc.Content.Start; object collEnd = combinedDoc.Content.End; Range rng2 = combinedDoc.Range(ref collStart, ref collEnd); object collapseEnd = Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd; rng2.Collapse(ref collapseEnd); // Paste range into resulting doc rng2.InsertFile(tempWordFilePath, ref missing, ref missing, ref missing, ref missing); object pageBrk = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak; rng2.InsertBreak(ref pageBrk); doc.Close(ref missing, ref missing, ref missing); File.Delete(tempWordFilePath); }

我在 MSDN 论坛上读到这可能是由于缺少名为 SHDocVw.dll 的库。我已经使用包含的库重新打包了我的应用程序,但结果相同。其他人说这可能是服务包问题,但没有任何推荐的解决方案。另一个人建议忽略“80010108”错误,但这个想法很快被 OP 驳回。我还在这里读到,这可能是由于某些互操作类的实例化/引用不正确,但我没有在我的代码中看到这种情况(或者我没有看到它?)



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有