10

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.

enter image description here

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

enter image description here

Community
  • 1
  • 1
Patrick
  • 3,073
  • 2
  • 22
  • 60

2 Answers2

17

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.

user1725145
  • 3,993
  • 2
  • 37
  • 58
Anton Pavlov
  • 196
  • 2
  • 4
2

Embed Interop types was not shown on the property pages for my assembly (as in the question above), so I edited the project files directly to fix this problem:

EmbedInteropTypes

user1725145
  • 3,993
  • 2
  • 37
  • 58