CS0436: Type conflicts with the imported type

It is worth noting that another way to get such warnings is by simply setting a project in visual studio to reference itself: References -> Solution -> etc etc (how I figured this gem out is left as an exercise to the reader ...)

Visual Studio will happily comply, only to throw a wall of warnings of the type described by OP during build, which is to be expected (upon reflection) since every single class etc is getting defined twice.


I had a web application I converted from ASP.NET 3.5 to 4.5 when I moved to VS2015. I started seeing this as a warning, but the solution would still compile. There were no circular references, and cleaning the solution and deleting the bin and obj folders didn't help.

It turns out that VS2015 wasn't happy with some of my classes in the App_Code folder. The classes in here had the same namespace as the rest of the web pages in the parent folder. Once I moved these classes out of the App_Code folder and to the top level of the web application, the warnings went away.


The only time conflicts occur is when two dependent classes include the same class. There are two workarounds:

  1. Disable the warning in classes that cause CS0436:

    #pragma warning disable 0436
    
  2. Have a separate instance of the class, uniquely named in each client project (undesirable from a maintenance point of view).

EDIT: There is also a solution: do what Mark suggests below, and mark duplicate classes internal.

Tags:

C#

Warnings