Operation failed, QueryInterface call on the COM component for the interface with IID failed due to Library not registered

3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;

namespace GridComplete
{
    public partial class Form1 : Form
    {
        private static Excel.Workbook MyBook;
        private static Excel.Application MyApp;
        private static Excel.Worksheet MySheet;

        private void bRun_Click(object sender, EventArgs e)
        {
            MyApp = new Excel.Application();
            MyApp.Visible = false;
            MyBook = MyApp.Workbooks.Open(tbFile1);
            MySheet = (Excel.Worksheet)MyBook.Sheets[1];

        }

    }
}

On the line that sets MyApp.Visible to false, I get the following unhandled exception:

An unhandled exception of type 'System.InvalidCastException' occurred in GridComplete.exe

Additional information: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

** I can't seem to figure what's going on. I tried to delete keys from the registry and rerun. That didn't work. I also fully uninstalled Microsoft Office, then reinstalled. I'm not sure what else to do to fix this issue.

c#
excel
asked on Stack Overflow Aug 22, 2014 by Marian Montagnino • edited Sep 15, 2014 by pnuts

1 Answer

1

It's possible that you don't have specified version of Microsoft Excel installed on computer where you running that code. Or it's installation broken. Try to re-install Office

answered on Stack Overflow Aug 22, 2014 by rufanov

User contributions licensed under CC BY-SA 3.0