开发者

How to deal with The type 'Foo' in 'File1.cs' conflicts with the imported type 'Foo' in 'File2.dll' warning

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. Pro开发者_Python百科ject 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!


The best case is to use different Namespaces.

So ProjectA

namespace Project.Library

ProjectB

namespace Project.Service

ProjectC

namespace Project.Test

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:

using Library = Project.Library;

namespace Project.Service
{
     public class User
     {
          public int GetUserId()
          {
              Library.User myLibUser = new Library.User();
              return myLibUser.Id;
          }
     }
}


When you access your type, fully qualify it (by calling it through namespace(s).class so there can't be ambiguity.

For instance:

  • MyNamespace.Foo
  • YourNamespace.Foo

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.


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.


Remove reference to your compiled file from Solution\References :)


In the Class Properties, change Build Action from Content to Compile


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜