.net “引用已创建到嵌入式互操作程序集”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8156488/
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
What does "reference was created to embedded interop assembly" mean?
提问by AngryHacker
I am getting the following warning:
我收到以下警告:
A reference was created to embedded interop assembly
c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Accessibility.dllbecause of an indirect reference to that assembly created by assemblyc:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Windows.Forms.dll. Consider changing the 'Embed Interop Types' property on either assembly.`
c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Accessibility.dll由于对程序集创建的程序集的间接引用,因此创建了对嵌入式互操作程序集 的引用c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Windows.Forms.dll。考虑更改任一程序集上的“嵌入互操作类型”属性。`
My assembly contains a reference to both Accessibility.dll and System.Windows.Forms.dll. Why am I getting this warning?
我的程序集包含对 Accessibility.dll 和 System.Windows.Forms.dll 的引用。为什么我会收到此警告?
Btw, the Accessibility.dll has 'Embed Interop Types=true' while System.Windows.Forms.dll has it set to false.
顺便说一句,Accessibility.dll 具有“Embed Interop Types=true”,而 System.Windows.Forms.dll 将其设置为 false。
回答by KreepN
Per the MSDN:
根据 MSDN:
"You have added a reference to an assembly (assembly1) that has the Embed Interop Types property set to True. This instructs the compiler to embed interop type information from that assembly. However, the compiler cannot embed interop type information from that assembly because another assembly that you have referenced (assembly2) also references that assembly (assembly1) and has the Embed Interop Types property set to False."
“您添加了对一个程序集 (assembly1) 的引用,该程序集的 Embed Interop Types 属性设置为 True。这指示编译器从该程序集中嵌入互操作类型信息。但是,编译器无法从该程序集中嵌入互操作类型信息,因为另一个您引用的程序集 (assembly2) 也引用了该程序集 (assembly1),并且将 Embed Interop Types 属性设置为 False。”
To address this warning
为了解决这个警告
To embed interop type information for both assemblies, set the Embed Interop Types property on all references to assembly1 to True.
要为两个程序集嵌入互操作类型信息,请将所有对程序集 1 的引用的“嵌入互操作类型”属性设置为 True。
This means you must change 'Embed Interop Types=true' on System.Windows.Forms.dll
这意味着您必须在 System.Windows.Forms.dll 上更改“Embed Interop Types=true”
or
或者
To remove the warning, you can set the Embed Interop Types property of assembly1 to False. In this case, interop type information is provided by a primary interop assembly (PIA).
要删除警告,您可以将 assembly1 的 Embed Interop Types 属性设置为 False。在这种情况下,互操作类型信息由主互操作程序集 (PIA) 提供。

