Bryuk
Bryuk

Reputation: 3345

using Excel = Microsoft.Office.Interop.Excel Compilation Error

In my MVC 5 Application I want to use Microsoft.Office.Interop.Excel library. I use Visual Studio 2013 and Office 2013. I added a reference Microsoft.Excel 15.0 Object Library and in my class I added using Excel = Microsoft.Office.Interop.Excel; When I click build it doesn't shows any error and tells that Build Complete, but when I run my Application I'm getting this error

 Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1748: Cannot find the interop type that matches the embedded interop type 'Microsoft.Office.Interop.Excel.Application'. Are you missing an assembly reference?

Source Error:

[No relevant source lines]

Source File:    Line: 0 

What it could be?

Upvotes: 4

Views: 6658

Answers (3)

Dave Cousineau
Dave Cousineau

Reputation: 13148

This happens to me if I export an interop type. If the error is about Excel.Application then look for a public method or property on a public class that returns an Application reference or has an Application reference as a parameter (anything public that makes an interop type visible).

Either hide that class, property, or method by making it private or internal, or don't return that type, or wrap the interop type in your own wrapper class and return that instead (which is better practice anyways.)

Upvotes: 0

Praveen
Praveen

Reputation: 195

Adding the reference dll file into the Bin folder will help to resolve this issue.

Upvotes: -1

Jernej Novak
Jernej Novak

Reputation: 3283

You have assemblies for MS 2010 but you have installed office 2013. Assemblies are not forward compatible. You must install office the same version that your DLLs are or better use something like OpenXml sdk.

Then it looks that some necessary assembly is missing. You will have to add reference to assembly.

Cannot find the interop type that matches the embedded interop type ''. Are you missing an assembly reference? This method is similar to the previous error in that it occurs if one assembly embeds type information and another does not. In this case, you have an assembly, assembly1, that references a PIA assembly with Embed Interop Types is set to true. Assembly1 then exposes a type from the PIA assembly, for example as the return type from a method or property. Another assembly, assembly2, references assembly1 and makes use of the embedded type. The error occurs if assembly2 does not also reference the PIA assembly, and therefore cannot locate the embedded type information. To resolve the issue, you need to add a reference from the second assembly to the PIA assembly and set the Embed Interop Types property to true. Thus, both assemblies will have a reference to the PIA assembly, with type information embedded, and both can utilize the embedded type.

http://blogs.msdn.com/b/vbteam/archive/2010/06/11/troubleshooting-errors-when-embedding-type-information-doug-rothaus.aspx

Upvotes: 9

Related Questions