5
votes

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;
        }
    }
2
this is way too generic, can you give examples and where you are getting this?Shane_Yo
is it the right version of word and where your running it? - you need the same as your interop version or newer. Microsoft don't recommend using office interop in a server environment - are you?Shane_Yo
My system don't have office installed.user3505449
If you don't have office installed, then the error is fully expected.Simon Mourier

2 Answers

5
votes

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

0
votes

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...