Running Microsoft.Office.Interop.Excel Tests in Hudson
A customer project that I’m currently working on was giving us fits because our continuous integration server would hang on some of our integration tests.
We use the Microsoft.Office.Interop.Excel COM objects to read in an Excel spreadsheet and parse some data. We open the spreadsheet with the Workbooks.Open method. All of our integration tests that call this code run just fine on our developers’ machines.
Our CI server is Hudson. Searching through the Hudson logs, we could see that Hudson would hang in any test that calls the code that opens an Excel spreadsheet. Those tests were throwing this exception:
System.Runtime.InteropServices.COMException : Microsoft Excel cannot access the file 'C:\hudson\jobs\TestApp\workspace\TestAppTests\bin\Debug\TestData\textExcelFile.xlsx'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook. +++++++++++++++++++ STACK TRACE: at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
After some search on the Internet, I found a thread on UReader.com that pointed us in the right direction towards solving this problem.
The problem is that the Workbooks.Open method fails when called from a service. In our case, the service is Hudson. Apparently there is a permissions problem that prevents Excel from accessing files.
The solution to the problem is:
- Stop the service.
- Run dcomcnfg.
- Navigate to Component Services –> Computers –> My Computer –> DCOM Config –> Microsoft Excel Application.
- Right click on it and select Properties.
- Now set the account to use to run the application. In our case, we selected the “This User” radio button, and entered the user and password for the account that we run Hudson from.
- Close dcomcnfg and restart the service.
We are very happy to now have our CI server running smoothly.
No comments
Category:
