12

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?

Frank C.
  • 7,758
  • 4
  • 35
  • 45
David
  • 2,298
  • 6
  • 22
  • 56
  • What is the output of `dir C:\WINDOWS\assembly\GAC_MSIL\Office\15.0.0.0__71e9bce111e9429c\Office.dll` on your system (i.e. is the referenced file actually present)? – Dirk Vollmar Sep 14 '16 at 13:52
  • 2
    I ran into that exception once, it just popped up between debug builds out of nowhere. For me, in the end all I did was Build>Clean the solution and then Build>Rebuild it and the exception disappeared so that might be worth a try – soohoonigan Sep 14 '16 at 13:53
  • 2
    If @soohoonigan's suggestion doe not work, delete the Office references and then add then again. The `cannot find the file` error makes me wonder if your IT department ran some update while you were at lunch. – TnTinMn Sep 14 '16 at 13:58
  • @TnTinMn Thank you, this fixed it, not sure what happened there, but it's working now – David Sep 14 '16 at 14:04

5 Answers5

16

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.
David
  • 2,298
  • 6
  • 22
  • 56
  • I tried but doest work, my error on embed interdrop types from microsoft.visualstudio.shell.interdrop because it missing the interdropservices.guidattribute :/ I dont know it funny :D I tried at properties close the embed interdrop feature – Çağlar Can Sarıkaya Jun 28 '22 at 08:41
5

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.

Omer
  • 98
  • 1
  • 7
4

The actual problem is that a reference in your solution is set to embed Interop Types to the target assembly! just check the properties of your references and set to all of them that flag to false.

3

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'.

Myfero
  • 204
  • 3
  • 7
2

The default is "true", not "false". So by removing it and adding it again you are setting it to "true".

LordWabbit
  • 147
  • 5