-1

I made a very simple c# program for testing the access to some file path for different users. For everyone the program works fine, but for one user the program return the exception

System.io.filenotfoundexception: retrieving the COM class factory component with CLSID{} failed due to the following error: 80070002

and this happen when he try to create a Microsoft.Office.Interop.Excel.Application object.

        using System;
        using System.Runtime.InteropServices;
        using Excel = Microsoft.Office.Interop.Excel;
        using System.Windows.Forms;
        using System.Diagnostics;
        namespace TestExcelBianchi
        {
            class Program
            {
                static void Main(string[] args)
                {
        
                   
                    ...
    
                    Excel.Application excel = new Excel.Application();
                    Excel.Workbook wb=null;
                    ....
                }
            }
    }

This issue started to happen after running the Office repair on the user pc, probably is missing the office PIA. Do I need to reinstall office on the user machine or is there a way to avoid it?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
TemoZat
  • 23
  • 1
  • 5
  • You already identified the issue yourself. The application is not finding a dll or its dependency required to run. You can try to repair office again and if that doesnt work, reinstall it. You may be able to diagnose the issue more by looking the dll that contain the Excel class and its dependencies (https://stackoverflow.com/questions/7378959/how-to-check-for-dll-dependency) to see what dll is causing the issue. – falopsy Nov 18 '21 at 11:17

1 Answers1

0

It seems your machine is missing the required dependency. Try running the com component through Dependency Walker (depends.exe) to see if you have all of the required libraries installed. Or just try to repair/reinstall MS Office on the problematic machine.

See Can't instantiate COM component in C# - error 80070002 for more information about the issue.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45