如何处理类型“Foo”在“File1.cs”中与导入类型“Foo”冲突;在“File2.dll”中警告
我有以下解决方案结构: 项目A 项目B(WCF) 项目 C(单元测试)
我从项目 B 生成一个代理。然后该代理包含在项目 A 和项目 C 中。 项目 C 也引用项目 A。 结果,在编译时我收到了超过一千个以下类型的警告:
“File1.cs”中的类型“Foo”与“File2.dll”中导入的类型“Foo”冲突。
这个问题的最佳解决方案是什么?我尝试使用#PRAGMA IGNORE,但在这种情况下我找不到警告号。
谢谢!
I have the following solution structure:
Project A
Project B (WCF)
Project C (Unit Testing)
I generate a proxy from Project B. The proxy is then included in Project A and Project C.
Project C also references Project A.
As a result, when compiling I get over a thousand warnings of the type:
The type 'Foo' in 'File1.cs' conflicts with the imported type 'Foo' in 'File2.dll'.
What is the best solution to this problem? I tried using #PRAGMA IGNORE, but I couldn't find the warning number in this case.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
最好的情况是使用不同的命名空间。
所以 ProjectA
ProjectB
ProjectC
那么,你可以在你的冲突类中使用别名。
例如,假设 Project.Library.User 和 Project.Service.User 都存在。
您想在服务中访问图书馆的用户类,您可以这样做:
The best case is to use different Namespaces.
So ProjectA
ProjectB
ProjectC
Then, you can use an alias in your conflict class.
For example, say Project.Library.User and Project.Service.User both exist.
You want to access your library's user class in your service, you could do:
当您访问您的类型时,请完全限定它(通过通过命名空间调用它。class,这样就不会出现歧义。
例如:
所以您有相同的类名,但在不同的命名空间下。
如果如果您使用与导入的内容相同的命名空间(这不太可能),那么您或外部代码提供者将必须更改命名空间。
When you access your type, fully qualify it (by calling it through namespace(s).class so there can't be ambiguity.
For instance:
So you have same class name, but under different namespaces.
If in any chance you're using the same namespace as in the imported stuff (which is unlikely) then either you or the external code providers will have to change the namespace.
我也有同样的问题。我使用的是 VS 2010 Pro。我忽略了它大约10个小时;不仅仅是错误,还有编译时的错误。然后,嘭!
我所做的只是导航到
Build
选项卡并单击清理解决方案。问题解决了。请确保,您没有在 using 语句中处置任何不需要处置的内容。
I had the same problem. I am using VS 2010 Pro. I ignored it for about 10 hours; not just error but errors at complie time. Then, BAM!
All I did was navigate to the
Build
tab and click clean solution.Problem solved. Be sure, you aren't disposing anything in your using statements that need not be disposed.
从 Solution\References 中删除对已编译文件的引用:)
Remove reference to your compiled file from Solution\References :)
在类属性中,将构建操作从内容更改为编译
In the Class Properties, change Build Action from Content to Compile
当您知道自己在做什么时,可以使用 Pragma 0246 抑制警告。
我通过启动构建然后查看输出窗口找到了错误代码。
确保您在下拉列表中选择了“构建”。
When you know what you are doing, you can suppress the warnings with Pragma 0246.
I found the error code by starting a build and then look in the output window.
Make sure you have 'build' selected in the dropdown.