Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Embed Interop Types from Assembly

I know that similar questions have been asked on here before, but I'm not sure they actually solve my problem, unless I'm misunderstanding them.

I've been working on an application this morning and not had any issues building or rebuilding the solution, but after going for my lunch and then coming back (I left the program open), I suddenly am unable to build it, since it is returning 3 errors, the likes of which I've not come across before.

Error 1:

Cannot embed interop types from assembly 'office' because it is missing either the 'ImportedFromTypeLib' attribute or the 'PrimaryInteropAssembly' attribute.

Error 2:

Cannot embed interop types from assembly 'office' because it is missing the 'Guid' attribute

Error 3:

Unable to load referenced library 'C:\WINDOWS\assembly\GAC_MSIL\Office\15.0.0.0__71e9bce111e9429c\Office.dll': The system cannot find the file specified. C:\WINDOWS\assembly\GAC_MSIL\Office\15.0.0.0__71e9bce111e9429c\Office.dll

What is causing these errors to suddenly arise?

After checking in Project Properties > Reference > Add > COM, I can see that Office 15.0 Object Library is referenced. So what do I do? It just seems weird that they came about whilst the application was open?

like image 926
David Avatar asked Sep 14 '16 13:09

David


People also ask

How do I set the Embed Interop Type property?

In Solution Explorer, expand the References folder and select the TypeEquivalenceInterface reference. In the Properties pane, set Embed Interop Types to True.

What is embed interop types?

Embed Interop Types is a new feature of the . NET 4.0 Framework that allows you to include the attribute information that is normally stored in the Primary Interop Assembly (PIA) in the executable or dynamic-link library (DLL) instead.


3 Answers

I believe it is not the answer. Probably, you have marked Embed Interop Types in assembly properties window to 'true'. By remove&add reference you have set it to back to default value, which is 'false'.

like image 80
Myfero Avatar answered Oct 11 '22 04:10

Myfero


Just so this isn't unmarked for the rest of eternity and for any potential future users with the same problem, the answer is, as suggested by @soohoonigan and @TnTinMn:

  • Clean and rebuild the solution.
  • If that doesn't work, remove the references, and re-add them again.
like image 12
David Avatar answered Oct 18 '22 03:10

David


Seeing only errors 1 and 2, guided by the answers here and some further research, what solved the issue for me was:

References -> Microsoft.CSharp -> Properties - change 'Embed Interop Types' to 'False' and then rebuild.

like image 5
Omer Avatar answered Oct 18 '22 01:10

Omer