如何消除相互引用的库和可执行文件的类型冲突?
我有两个不同的文件,Foo1.exe 和 Foo2.dll。
当我尝试在 Foo1.exe 中使用 Foo2.dll 中声明的对象时,一切都按预期工作。
当我尝试在 Foo2.dll 中使用 Foo1.exe 中声明的对象时,一切都会按预期编译。
但是,当我尝试将对象从 Foo1.exe 传递到 Foo2.dll 时,Foo1.exe 无法编译,因为它的类型与 Foo2.dll 中的对象冲突,而 Foo2.dll 实际上并不存在,而只是从 Foo1.exe 引用。
如何使 Foo2.dll 可以引用 Foo1.exe,但在编译 Foo1.exe 时类型不会引起冲突?
实际的错误消息是 Foo1.cs 中的类型 Foo 与 Foo2.cs 中导入的类型 Foo 冲突
感谢您的帮助!
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 Foo1.cs conflicts with the imported type Foo in Foo2.cs
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您以某种方式设法让 Foo1.exe 引用 Foo2.dll 的另一个副本,该副本未引用 Foo1.exe。因为 C# 编译器会阻止您执行您想要执行的操作 - 即创建循环引用。
因此,您的编译甚至是侥幸,您应该尝试不同的方法。
您需要将 Foo1.exe 和 Foo2.dll 共用的类隔离到第三个程序集 Foo3.dll 中,两者都引用该程序集。那么 Foo3.dll 不应引用 Foo1.exe 或 Foo2.dll。
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.