Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 884
Bryuk Avatar asked Feb 14 '23 13:02

Bryuk


1 Answers

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

like image 146
Jernej Novak Avatar answered Feb 17 '23 04:02

Jernej Novak