Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

c# - Unit test with Microsoft.Office.Interop dll fails on build server

I've written a unit test. The code under test references Microsoft.Office.Interop.Excel.dll.

The test runs fine on my machine but fails on the build server. It fails on the line where the Excel application is instantiated:

var application = new Application { Visible = Visible };

The error is:

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

Does this mean I have to install the Redistributable Primary Interop Assemblies on my build server? And if so, do I also need to install Excel on the build server?

Edit: Microsoft.Office.Interop.Excel.dll is included in my solution and it is referenced from there.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you add Microsoft.Office.Interop.Excel.dll to the solution in a library folder and reference the assembly there the build machine should get the required assembly when you promote. Otherwise, you're referencing an assembly that comes with the installation of Excel. Also, if you try to distribute your application without putting it in the solution anyone who tries to run your application that doesn't have Excel installed will get run time errors.

Or course, you're other option if you do not want to redistribute the assembly is to put a try/catch around the code that calls the Excel assembly and then display a message to the user saying an installation of Excel is required.

Finally, each version of Excel (2010, 2007, etc) has different version numbers. Meaning, if you're using the 2010 assembly and someone has 2007 Excel installed they will get run time errors. The answer I ended up using for that was reflection to pick which assembly is used in their environment.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...