C# 不能跨程序集边界使用,因为它具有作为嵌入式互操作类型的泛型类型参数 [英] C# Cannot be used across assembly boundaries because it has a generic type parameters that is an embedded interop type

查看:44
本文介绍了C# 不能跨程序集边界使用,因为它具有作为嵌入式互操作类型的泛型类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 C# (wpf) 时遇到了这个错误.这个链接没有用

<块引用>

--编辑---正如所建议的那样,我通过更改图片中的道具将内嵌 = true 更改为 false,但错误仍然存​​在

解决方案

正如 WasGoodDone 所说,您需要为用于泛型的两个(所有)程序集使用相同的类.

换句话说,如果你有 assembly1,它引用了一些 interopAssemblyassembly2,它引用了相同的 interopAssembly,然后将 embedded interop type 切换为 true,然后您将拥有 interopAssembly两个 副本>.

如果你想使用一些从assembly1assembly2的交叉引用,.NET解决不了,因为从他们的角度来看,类是不同的.

当您关闭嵌入选项时,您的程序集将引用包含互操作类型的其他程序集.通过这种方式,您可以使用不同库中的互操作类型.

因此,如果您遇到上述问题,则意味着您至少有两个程序集引用了 PCDLRN,并且您必须在所有这些程序集中关闭 embedded interop type.

I am facing this error with C# (wpf). This link has not been useful

Cannot be used across assembly boundaries because it has a generic type parameters that is an embedded interop type

Just to explain the structure of my program I can tell that:

I am using a library made by an external company. We can call it PCDLRN

In the solution I have a project made by me which incluse the types in the previous lib. In my library I define:

public ObservableCollection<PCDLRN.DimensionCmd> obcPcdlrnDimensionCommands = new ObservableCollection<PCDLRN.DimensionCmd>();

in order to by used in my main program. So in short:

PCDLRN->MYLIB obcPcdlrnDimensionCommands --> MY PROGRAM myPcd.obcPcdlrnDimensionCommands

in my program I want to access the aforementioned ObservableCollection but it doesn't build giving the error in the title.

--EDIT--- As suggested I have changed from embedded = true to false by changing the prop as in picture but the error remains

解决方案

As WasGoodDone remarked, you need to use the same class for both (all) assemblies you use for generics.

In other words, if you have assembly1, that references some interopAssembly, and assembly2, that references the same interopAssembly, and you switch embedded interop type to true, then you will have two copies of types from interopAssembly.

If you want to use some cross-references from assembly1 to assembly2, .NET can't resolve it, because from their point of view, the classes are different.

When you switch the embedded option off, your assembly will reference the other assembly which contains the interop types. And in this way you can use the interop types in different libraries.

So, if you have the problem described above, it means that you have at least two assemblies referencing PCDLRN, and you must switch off embedded interop type in all of them.

这篇关于C# 不能跨程序集边界使用,因为它具有作为嵌入式互操作类型的泛型类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆