Unable to open Excel when i run build (vstest) in azure devops pipeline


I am using Microsoft.Office.Interop.Excel to open the excel workbook to do some automation for a given project. When i run my build, i encountered this error

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

Which comes from this code in my visual studios. excel.Application x1app = new excel.Application();

I am able to run the test locally but when i run it in azure devops, it dosen't work. I believe it is because devops does not have excel inside thus unable to execute the code.

  1. Is there any way i can solve this error while still using interop?
  2. Are there any alternatives i can try besides EPPlus.

    excel.Application x1app = new excel.Application(); x1app.SheetsInNewWorkbook = 1; x1app.Visible = true; excel.Workbook x1workbook = x1app.Workbooks.Open(); excel.Workbook NewWorkBook = x1app.Workbooks.Add(); for (sheets) { excel._Worksheet x1worksheet = x1workbook.Sheets[x]; x1worksheet.Copy(Type.Missing, After: NewWorkBook.Sheets[x - 3]); } Thread.Sleep(2000);

I should be able to run the build successfully on devops

asked on Stack Overflow Jul 25, 2019 by mandog • edited Jul 25, 2019 by (unknown user)

1 Answer


According to your description, what you are doing required Excel installed on the build agent.

If you are using host build agent in Azure DevOps. It seems not be installed on the machines. You could find a full list of software which is installed on machines in the Azure Pipelines Hosted agent pool such as this Azure Pipelines Hosted VS2017 image.

As a workaround, if Microsoft-hosted agents don't meet your needs, then you can deploy your own self-hosted agents.

Just need to make sure your self host agent environment is the same as your local development environment.

Besides, not totally clearly about your detail useage of excel. You could also try to use openxml. Please take a look at this similar question here: How can I build a project containing Excel creation in VSTS?

answered on Stack Overflow Jul 26, 2019 by PatrickLu-MSFT

User contributions licensed under CC BY-SA 3.0