Excel – Different Interop references on two different computers doesn’t work


When I add a reference to Microsoft.Office.Interop.Excel on my computer, Visual Studio adds this to the project file:

<COMReference Include="Excel">

There is another developer on the team who gets errors and needs to add a DLL file to the project called Interop.Excel.dll, which replaces the code above with this in the project file:

<Reference Include="Interop.Excel, Version=, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>My Project\Interop.Excel.dll</HintPath>

This does work on my computer.

Could you please explain the differences between the two methods, which is best, and how to get the first one working on other computers?

Best Answer

I don't see a problem with your approach either.

Typically VS will generate an interop assembly for COM components automatically when you add a reference to the component. However, when you add a reference to one of the Office components (XP or any later version), a reference to the pregenerated (and optimized) primary interop assembly from Microsoft is added as in your first example. The line


means that this PIA is used.

If you correctly added the PIA reference the CopyLocal property of this reference should be set to false and the Path property should be something like


You will find some more details on interop assemblies in this MSDN article.

To get the first method working it is necessary that the Office Primary Interop Assemblies (PIAs) are installed on the machine. There is a redistributable version available from Microsoft:

AFAIK, these PIAs only get installed by the Office setup when the .NET Framework has already been installed, that's why there is a separate redistributable for the PIAs.

Note: Make sure that you reference the version of Office that you are targeting. When targeting several versions of Office, you might get some problems however. A solution in that case might be late binding (if performance is not an issue).

Related Topic