5

How to solve below error. This error getting at run time.

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Code: This code is for convert word to pdf document file. I getting error at this line.

Application wordApp = new Microsoft.Office.Interop.Word.Application();
Document wordDocument = new Document();           
private void ConvertWord2PDF(string inputFile, string outputPath)
{

        try
        {
            if (outputPath.Equals("") || !File.Exists(inputFile))
            {
                throw new Exception("Either file does not exist or invalid output path");
            }

            // app to open the document belower
            Application wordApp = new Microsoft.Office.Interop.Word.Application();
            Document wordDocument = new Document();

            // input variables
            object objInputFile = inputFile;
            object missParam = Type.Missing;

            wordDocument = wordApp.Documents.Open(ref objInputFile, ref missParam, ref missParam, ref missParam,
                ref missParam, ref missParam, ref missParam, ref missParam, ref missParam, ref missParam,
                ref missParam, ref missParam, ref missParam, ref missParam, ref missParam, ref missParam);

            if (wordDocument != null)
            {
                // make the convertion
                wordDocument.ExportAsFixedFormat(outputPath, WdExportFormat.wdExportFormatPDF, false,
                    WdExportOptimizeFor.wdExportOptimizeForOnScreen, WdExportRange.wdExportAllDocument,
                    0, 0, WdExportItem.wdExportDocumentContent, true, true,
                    WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missParam);
            }

            // close document and quit application
            wordDocument.Close();
            wordApp.Quit();

            Response.Write("File successfully converted");
            //ClearTextBoxes();
        }
        catch (Exception e)
        {
            throw e;
        }
    }
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
user3505449
  • 71
  • 1
  • 1
  • 8

2 Answers2

5

no Office app should be used in a service or in a web-app, such as IIS. Secondly, interop.word.dll is like a header file and you actually need to have Office\word installed to be able to use it.

Please be warned of Microsoft's stance on this:

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

Preview and convert Word files in ASP.Net -using OpenXML

Shane_Yo
  • 770
  • 8
  • 24
  • Solution: Install Microsoft Office in the instance running the program. But this is only if you are sure that you want to go against Microsoft's recommendations. – Joshua Swain Dec 11 '20 at 14:24
0

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Looks like you're doing server-side automation of Office, which is a no-no, here is why:

Considerations for server-side Automation of Office

On the server side its much more reliable (and supported) to use OpenXML or better yet ClosedXML instead and process them as docx files. Since you're converting to PDF I recommend you check out this QA...

Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321