Where does error CS0433 "Type 'X' already exists in both A.dll and B.dll " come from?

When I run a webapp from Visual Studio 2008 SP1 using the internal web server (not IIS) I receive the above mentioned error.

The full error (source file Default.aspx.cs):

Compiler Error Message: CS0433: The type 'WebApplication3.Site1' exists in both 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_site1.master.cdcab7d2.muczzy9v.dll' and 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\assembly\dl3\44c3a3cf\80dd34ed_6968ca01\WebApplication3.DLL'

The preceding full warning:

Warning: CS0436: The type 'WebApplication3._Default' in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs' conflicts with the imported type 'WebApplication3._Default' in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\assembly\dl3\44c3a3cf\e096e61c_6568ca01\WebApplication3.DLL'. Using the type defined in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\aa563bcf\59deedc0\App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs'.

Source of warning points to an intermediate file App_Web_default.aspx.cdcab7d2._tlkwdos.0.cs:

Line 162:    
Line 163:    [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 164:    public class default_aspx : global::WebApplication3._Default, System.Web.IHttpHandler {
Line 165:        
Line 166:        private static bool @__initialized;

and my question: where does this come from?

The webapp (not website!) has one Default.aspx and one Site1.Master, no dependencies. They're almost empty, with an asp:Label on the page. Previously, this webapp worked fine. When I remove any references in Default.aspx.cs to the master, all goes well. The master has some code only.

It's actually one of many little fire-and-forget test webapps, so I couldn't care less. But I hadn't seen this before and now I'm curious of what to do, other then copying code into a new project (cleaning solution doesn't help).

Note: I've read this post and some others, they don't apply.

To resolve this error, use the alias feature of the -reference (C# Compiler Options) compiler option or do not reference one of your assemblies. This error can also occur in ASP.NET Web Forms if: The @ Page directive has a CodeFile attribute when it should be a CodeBehind attribute. Code is placed in an App_Code folder that shouldn't reside there.

20 Answers 20 ---Accepted---Accepted---Accepted---Theory. When this issue is not caused by a bug in the application (e.g., duplicate class name):. This issue appears to present after a change is made to the application's project that results in a new build (e.g., code/reference/resource change).

This might happen if you place .cs files in App_Code and changed their build action to compile in a Web Application Project.

Either have the build action for the .cs files in App_Code as Content or change the name of App_Code to something else. I changed the name since intellisense won't fix .cs files marked as content.

More info at http://vishaljoshi.blogspot.se/2009/07/appcode-folder-doesnt-work-with-web.html

Does anyone know how to determine which file causes the build of the TEMP dll ? The site is a classic ASP site built on .NETFramework 2.0 (C# code behind). This has been driving me nuts for a couple of weeks now.

Look at the Inherits tag of all your aspx pages and master pages. Chances are there are two partial classes that have the same name. Change one and recompile.

Here is some more info:


error CS0433: The type 'Element' exists in both 'APIDBAPI, Version=, Culture=neutral, PublicKeyToken=null' and 'APIUIAPI, Version=, Culture=neutral, PublicKeyToken=null'. Thanks. Solved!

I still had the problem after all these suggestions. Some class inside App_Code was being compiled to two DLL's. Something like this (simplified):

warning CS0436: The type 'HcmDbGeographyModelBinder' in 

'<user_profile_dir>\AppData\Local\Temp\Temporary ASP.NET Files\temp\3b1ed8ee\11405e8e\App_Code.oqr0kusq.0.cs' 

conflicts with the imported type 'HcmDbGeographyModelBinder' in 

'<user_profile_dir>\AppData\Local\Temp\Temporary ASP.NET Files\temp\3b1ed8ee\11405e8e\assembly\dl3\ea0aa3ee\6022e6d5_2cc8cf01\HCM.Web.Backoffice.DLL'.

I just renamed the "App_Code" folder to "Code". This is a MVC5 project, so there shouldn't be a problem with serving .cs files inside the web project's root.

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100

Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.

CS0436: Type conflicts with the imported type (3) . I am including an instance of the same source files in multiple assemblies using the Add As Link option.

Theory. When this issue is not caused by a bug in the application (e.g., duplicate class name):. This issue appears to present after a change is made to the application's project that results in a new build (e.g., code/reference/resource change).

  • PS: my main thought is: something screwed the temp dir, and my main way out here is to simply remove the temp dir by hand and rebuild. Not tried yet (would remove the "evidence"), in case somebody has a deeper insight here.
  • This post clearly augments the original accepted answer. Good explanation and clear steps, thanks!
  • @Abel please consider making this the answer. Because only cleaning the ASP.NET temp folder won't help!
  • This happened to me with a non-web project. Just deleting the bin and obj folders fixed it.
  • @ArinGhazarian, exactly! I had to delete the obj and bin folders as well to clear up this error.
  • Great answer with a great explanation. Thank you!
  • Yeah, that'll probably work (see my own comment above), but I hoped for a tad more insight in where this came from and what to do to prevent it (or even, make it reproducible). I'm not against solving brute force, but before doing so, I like to understand what's going on.
  • This has happened to me in the past. I believe it's a problem with VS where it doesn't clean up after a debugging session or before starting a new one. Last time this happened to me was with VS2005 a couple of years back.
  • Accepted this as answer because it is a solution. However, it does not explain "why". If I find a better solution or a and actual reason, I'll update Lyman's answer or add my own.
  • Actually this answer doesn't work for me. My project was working well a couple of weeks ago, but I tried today and shows the above said issue. I deleted the temp files as stated above (for Windows 7) and the same issue persists. I am still wondering why...
  • @VenugopalM did you find any other solution, solution above didnt worked for me
  • The link you provided was the solution for me. I moved all my classes from the App_Code folder and put them in a new folder named Classes. Then renamed the namespaces of the classes (end of namespace = .Classes instead of .App_Code). And of course, update all the using statements and references to the App_Code folder.