Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Cannot be used across assembly boundaries because it has a generic type parameters that is an 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.

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

like image 379
Patrick Avatar asked Feb 08 '16 13:02

Patrick


2 Answers

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.

like image 114
Anton Pavlov Avatar answered Mar 13 '23 14:03

Anton Pavlov


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

like image 30
user1725145 Avatar answered Mar 13 '23 14:03

user1725145