什么"引用是为了嵌入的互操作装配"意味着?是为了、操作、QUOT

2023-09-02 10:45:10 作者:Sober (清醒)

我收到以下警告:

一个参考的建立是为了嵌入互操作程序集 C: Program Files文件(x86)的参考大会微软框架 .NETFramework V4.0 Accessibility.dll 由于间接引用该程序集被组装创建 C: Program Files文件(x86)的参考大会微软框架 .NETFramework V4.0 System.Windows.Forms.dll中。考虑更改在任assembly.`的嵌入互操作类型属性。

A reference was created to embedded interop assembly c:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.0Accessibility.dll because of an indirect reference to that assembly created by assembly c:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.0System.Windows.Forms.dll. Consider changing the 'Embed Interop Types' property on either assembly.`

我的组件中引用了两个Accessibility.dll和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中有它设置为false。

Btw, the Accessibility.dll has 'Embed Interop Types=true' while System.Windows.Forms.dll has it set to false.

推荐答案

每MSDN的:

你已经添加了一个参考的组件(assembly1)具有嵌入互操作类型属性设置为True,这指示编译器从组件嵌入互操作类型的信息。从不过,编译器无法嵌入互操作类型信息装配,因为你已经引用另一个组件(assembly2)也引用了组件(assembly1),并有嵌入互操作类型属性设置为False。

"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为True。

这意味着你必须在System.Windows.Forms.dll中更改嵌入互操作类型=真正的

要删除警告,可以assembly1的嵌入互操作类型属性设置为False。在这种情况下,互操作型信息由主互操作程序集(PIA)提供。

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