Search code examples
c#wpfmultithreadingms-wordoffice-interop

Getting 'Compile error in hidden module: SmartTagsMod' while opening a word document in MS Word 2010


I am converting a large number of MS Word documents to PDFs using the Interop library in a multi-threaded WPF application (.NET Framework 4). I get the following error on some word documents:

Screenshot of the error

It blocks the current thread until I click OK on the dialog and then continues with the conversion and the converted PDF comes out to be fine as well.

This only happens on certain documents. I am running the application on multiple computers and this has occured on other computers too.

Below is my code for conversion:

var wordApplication = new Microsoft.Office.Interop.Word.Application();
// Opening the word document
var wordDocument = wordApplication.Documents.Open(tempFile, false, true, false, NoEncodingDialog: false);
// Exporting the document to the PDF
wordDocument.ExportAsFixedFormat(pdfPath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
// Closing the document and the application.
((Microsoft.Office.Interop.Word._Document)wordDocument).Close(false);
((Microsoft.Office.Interop.Word._Application)wordApplication).Quit(false);
Marshal.ReleaseComObject(wordDocument);
Marshal.ReleaseComObject(wordApplication);
wordDocument = null;
wordApplication = null;

Does anyone know what could be causing this? Or whether I can close this dialog box from my application?

Thanks


Solution

  • wordApplication.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
    

    This seem to have fixed the issue.

    Thanks bibadia for providing the link to the question that had the fix.