vb.net 无法从程序集中嵌入互操作类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39491801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot Embed Interop Types from Assembly
提问by David
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.
我今天早上一直在开发一个应用程序,在构建或重建解决方案时没有遇到任何问题,但是在去吃午饭然后回来(我让程序保持打开状态)之后,我突然无法构建它,因为它是返回 3 个错误,我以前从未遇到过类似的错误。
Error 1:
错误 1:
Cannot embed interop types from assembly 'office' because it is missing either the 'ImportedFromTypeLib' attribute or the 'PrimaryInteropAssembly' attribute.
无法从程序集“office”嵌入互操作类型,因为它缺少“ImportedFromTypeLib”属性或“PrimaryInteropAssembly”属性。
Error 2:
错误 2:
Cannot embed interop types from assembly 'office' because it is missing the 'Guid' attribute
无法从程序集“office”嵌入互操作类型,因为它缺少“Guid”属性
Error 3:
错误 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
无法加载引用的库 'C:\WINDOWS\assembly\GAC_MSIL\Office\15.0.0.0__71e9bce111e9429c\Office.dll':系统找不到指定的文件。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?
检查项目属性 > 引用 > 添加 > COM 后,我可以看到引用了 Office 15.0 对象库。那我该怎么办?在应用程序打开时它们出现似乎很奇怪?
回答by David
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:
正因为如此,这在永恒的剩余时间以及对于任何潜在的未来用户遇到相同问题时都不会被取消,答案是,正如@soohoonigan 和@TnTinMn 所建议的那样:
- Clean and rebuild the solution.
- If that doesn't work, remove the references, and re-add them again.
- 清洁并重建解决方案。
- 如果这不起作用,请删除引用,然后重新添加它们。
回答by LordWabbit
The default is "true", not "false". So by removing it and adding it again you are setting it to "true".
默认值为“真”,而不是“假”。因此,通过删除它并再次添加它,您将其设置为“true”。
回答by Omer
Seeing only errors 1 and 2, guided by the answers here and some further research, what solved the issue for me was:
在此处的答案和一些进一步研究的指导下,只看到错误 1 和 2,对我来说解决问题的是:
References -> Microsoft.CSharp -> Properties - change 'Embed Interop Types' to 'False' and then rebuild.
参考 -> Microsoft.CSharp -> 属性 - 将“嵌入互操作类型”更改为“假”,然后重建。
回答by chris costa
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.
实际问题是您的解决方案中的引用设置为将互操作类型嵌入到目标程序集!只需检查您的引用的属性并将所有这些属性设置为false。
回答by Myfero
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'.
我相信这不是答案。可能您已将程序集属性窗口中的嵌入互操作类型标记为“true”。通过 remove&add 引用,您已将其设置回默认值,即“false”。

