Can't get Microsoft.Office.Interop reference to work

c#, office-interop, winforms

Solution

You need to add the library assembly reference to your project. They are referred to as "Primary Interop Assemblies".

(Assuming Visual Studio 2010)

Procedure

- open the solution explorer window

- expand your project folder accordion.

- right click on the references element

- select "add reference" from the dropdown

- select the .NET tab and look for the object library called `Microsoft.Office.Interop.Excel`.

- click ok

The object library should now appear in your references.

Problem

I have a C# winforms app and I am simply trying to open an Excel sheet. When I try to add a reference to Microsoft.Office.Interop, the "Office" part is red and says "Can't resolve symbol 'Office'". When I attempt to build, the error is: ``` The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) ``` I have Office 2012 installed, and I think I have the Primary Interop Assemblies installed... but I'm not positive. I know that this should be so easy, but I've been looking around for an answer to this for almost an hour and just can't figure it out. Thanks in advance!

Original source