Error closing Word doc: "The message filter showed that the application is busy."

I use Microsoft Interop to save a Word Doc as an HTML file, and I get this error when I try to close a document:

The message filter showed that the application was busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

Here is my code:

// word interop setting object visible = true; object readOnly = true; object missing = Type.Missing; object saveChanges = true; object htmlFile = (object)Server.MapPath(@"worddoc.html"); object fileType = (object)Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML; // open document Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(ref url, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref visible, ref missing, ref missing, ref missing, ref missing); try { // save the file wordDoc.SaveAs(ref htmlFile, ref fileType, 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); } catch (System.Exception ex) { saveChanges = false; } finally { wordDoc.Close(ref saveChanges, ref missing, ref missing); // ERROR HERE wordApp.Quit(ref saveChanges, ref missing, ref missing); wordDoc = null; wordApp = null; } 

Does anyone know what I'm doing wrong?

+4
source share
1 answer

There is nothing wrong with the code. The problem is that you run it in an unsupported configuration, and the behavior of the office is undefined in this situation (runs under asp.net)

Microsoft does not currently recommend or support Automation of Microsoft Office applications from any automated, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit erratic behavior and / or deadlocks when Office launched in this environment.

For more information:

http://support.microsoft.com/kb/257757

However, you can use the VSTO server class to work with office documents without starting Office.

+6
source

Source: https://habr.com/ru/post/893858/


All Articles