开发者

How to remove type conflicts with a library and executable that reference each other?

开发者 https://www.devze.com 2023-03-08 02:59 出处:网络
I have two different files, Foo1.exe and Foo2.dll. When I try to use an object declared in Foo2.dll in Foo1.exe, everything works as expected.

I have two different files, Foo1.exe and Foo2.dll.

When I try to use an object declared in Foo2.dll in Foo1.exe, everything works as expected.

When I try to use an object declared in Foo1.exe in Foo2.dll, everything compiles as expected.

But when I try to pass an object from Foo1.exe to Foo2.dll, Foo1.exe cannot compile because it has a type conflicting with an object in Foo2.dll which is not actually there, but was just referenced from Foo1.exe.

How do I make it so Foo2.dll can reference Foo1.exe, but the types do not cause conflictions when compiling Foo1.exe?

The actual error message is The type Foo in Fo开发者_Go百科o1.cs conflicts with the imported type Foo in Foo2.cs

Thanks for any help!


You have somehow managed to have Foo1.exe reference a different copy of Foo2.dll that doesn't reference Foo1.exe. Because the C# compiler will prevent you from doing what you're trying to do - which is create circular references.

So the fact that yours is even compiling is a fluke and you should try a different approach.

You need to isolate the classes that are common to both Foo1.exe and Foo2.dll into a third assembly, Foo3.dll which is referenced by both. Then Foo3.dll should reference neither Foo1.exe or Foo2.dll.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号