• Sign In
 
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...
Common Tasks
  • Blog Home
  • Email Blog Author
  • RSS for comments
  • RSS for posts
Search
  • Advanced search options...
Tags
  • .NET Framewor
  • .NET Framework
  • Ajax/Javascript
  • ASP.NET
  • CLR
  • Cool stuff
  • DataAccess
  • Debugging/Windbg
  • Hotfix/Service Pack
  • IDEVDataCollector
  • IIS
  • Internet Explorer
  • Italian techs
  • LogParser
  • OT
  • Personal
  • Productivity
  • Random
  • Scripting/ASP
  • Security
  • Technology
  • Tools
  • Troubleshooting
  • Vista/Longhorn
  • Visual Studio
Archives
Archives
  • November 2010 (1)
  • October 2010 (1)
  • July 2010 (2)
  • April 2010 (1)
  • March 2010 (2)
  • February 2010 (2)
  • January 2010 (1)
  • October 2009 (2)
  • September 2009 (2)
  • August 2009 (1)
  • July 2009 (5)
  • June 2009 (1)
  • May 2009 (1)
  • April 2009 (3)
  • March 2009 (3)
  • February 2009 (5)
  • January 2009 (3)
  • December 2008 (5)
  • November 2008 (3)
  • October 2008 (2)
  • September 2008 (3)
  • August 2008 (3)
  • July 2008 (3)
  • June 2008 (5)
  • May 2008 (4)
  • April 2008 (8)
  • March 2008 (4)
  • February 2008 (5)
  • January 2008 (2)
  • December 2007 (4)
  • November 2007 (6)
  • October 2007 (6)
  • September 2007 (8)
  • August 2007 (6)
  • July 2007 (7)
  • June 2007 (10)
  • May 2007 (9)
  • April 2007 (12)
  • March 2007 (8)
  • February 2007 (5)
  • January 2007 (3)
  • December 2006 (1)
  • November 2006 (4)
  • October 2006 (2)
  • September 2006 (9)
  • August 2006 (2)
  • July 2006 (1)

Compiler Error Message: CS0433 in ASP.NET 2.0

MSDN Blogs > Never doubt thy debugger > Compiler Error Message: CS0433 in ASP.NET 2.0

Compiler Error Message: CS0433 in ASP.NET 2.0

Rate This
Carlo Cardella
12 Jun 2007 2:11 AM
  • Comments 36

A few days ago a friend of mine had the Compiler Error Message: CS0433 error in his precompiled site, and proposed me a deal: a dinner for my help smile_regular, and since also Support Engineers sometimes need to eat, I accepted smile_wink.

The exact error message was the following: The type <typename> esists in both <path 1> and <path 2>. Sometimes the error message is quite self explanatory, especially if one of the two assemblies is in BIN and the other is in the GAC (remove the one in the BIN, you don't need two copies of the same file!), but my friend was getting the following one:

Exception information:
    Exception type: HttpCompileException
    Exception message: c:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\customers\30216428\89bd3cad\App_Web_default.aspx.27046288.rpug8fan.0.cs(112): error CS0433: The type 'App_Items_63_pgs_default' exists in both 'c:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\customers\30216428\89bd3cad\assembly\dl3\d1307a39\42cbc228_01a6c701\App_Web_tzn10d4k.DLL' and 'c:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\customers\30216428\89bd3cad\assembly\dl3\5493a6b9\8880bf21_01a6c701\App_Web_7jlq-fy_.DLL'

Thread information:
    Thread ID: 1
    Thread account name: <server>\ASPNET
    Is impersonating: False
    Stack trace:    at System.Web.Compilation.AssemblyBuilder.Compile()
   at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
   at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

As you can see, the two involved assemblies comes both from the Temporary ASP.NET Files folder and have randomly created names, so we needed some little more troubleshooting... I asked for the source code of the application and after flipping through a little bit, I notice he had a default.master page which he was using as the master for his default.aspx; interestingly both pages were implementing a class with the same name: public partial class App_Items_63_pgs_default.

That rang a bell... because what happens when you precompile the site is that you'll end up with two default.App_Item_63_pgs_default classes... I built a sample to confirm my theory:

   1: <%@ Master Language="C#" AutoEventWireup="true" CodeFile="default.master.cs" Inherits="_Default" %>
   2: <html xmlns="http://www.w3.org/1999/xhtml">
   3: <head runat="server">
   4:     <title>Untitled Page</title>
   5: </head>
   6: <body>
   7:     <form id="form1" runat="server">
   8:         <asp:Label ID="Label1" runat="server" Text="Master"></asp:Label>
   9:         <div>
  10:             <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
  11:             </asp:ContentPlaceHolder>
  12:         </div>
  13:         <asp:Label ID="Label2" runat="server" Text="Master"></asp:Label>
  14:     </form>
  15: </body>
  16: </html>
   1: <%@ Page Language="C#" MasterPageFile="~/default.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
   2:     Inherits="_Default" Title="Untitled Page" %>
   3:  
   4: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
   5:     <asp:Label ID="Label3" runat="server" Text="Content"></asp:Label>
   6: </asp:Content>

Publish the site and browse it, you should get the following error:

Server Error in '/TestPrecompiled' Application.


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0433: The type '_Default' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\TestPrecompiled\b3047f60\f7364c3\assembly\dl3\6d1b8849\12db42f6_e9abc701\App_Web_yvefexa5.DLL' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\TestPrecompiled\b3047f60\f7364c3\assembly\dl3\a4f9584b\913c83f6_e9abc701\App_Web_qmnuz7n3.DLL'

Source Error:
 
Line 110:    
Line 111:    [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 112:    public class default_aspx : global::_Default, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
Line 113:        
Line 114:        private static bool @__initialized;

Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\TestPrecompiled\b3047f60\f7364c3\App_Web_default.aspx.cdcab7d2.emhdmgwo.0.cs    Line: 112

Bingo! We have a repro! smile_regular  So I asked my friend to rename one of the two App_Item_63_pgs_default classes (or wrap them in two different namespaces) and the application magically started working fine.

I'm not completely clear why this happens only with the precompiled site while it works fine with the "normal" JITted site, but I'll try to find out.

It worth mentioning that you could get this compiler error if you upgrade your project to the Web Application Project you have with Visual Studio 2005 SP1 (or as a separate add-in); in that case pay attention to the @Page directive and change the CodeFile attribute to CodeBehind (further details in this post).

Again, when attempting to use the same CodeFile (.aspx.cs or .aspx.vb file) in Visual Studio 2005 for multiple ASPX or ASCX pages, compile errors resulted. Using a similar approach in Visual Studio .NET 2003 worked as desired. Visual Studio 2005 uses a “Partial Class” concept where declarations for “Controls” that are drag/dropped onto an ASPX page are put in a “.designer” file (which is typically stored in memory and not persisted to disk). The “designer” declarations are stored in the designer file and the actual C# or VB code is stored in the CodeFile. Because of the way that the ASPX/CodeFile/Designer go together, it isn’t straight forward to use multiple ASPX/Designer files with a single CodeFile since potentially unrelated controls from multiple ASPX pages will want to be declared in a single designer file. The recommended solution is to use the CodeFileBaseClass attribute of the ASPX page directive. When using this technique, each ASPX page has its own CodeFile/Designer files but then looks beyond these files for the base class that is specified.


Carlo

Quote of the Day:
Your heart often knows things before your mind does.
--Polly (Pearl) Adler
  • 36 Comments
ASP.NET, Visual Studio
Leave a Comment
  • Please add 7 and 2 and type the answer here:
  • Post
Comments
  • Richard
    15 Jun 2007 11:05 AM

    Having the same problem when precompiling an asp 2.0 app that I just converted from 1.1.

    Check out www.AlpacaDepot.com

    June 15, 2007

  • Carlo Cardella
    15 Jun 2007 11:39 AM

    Richard, have you checked your @Page directive? From my post above: "It worth mentioning that you could get this compiler error if you upgrade your project to the Web Application Project you have with Visual Studio 2005 SP1 (or as a separate add-in); in that case pay attention to the @Page directive and change the CodeFile attribute to CodeBehind (further details in this post)."

    If this does not help, I suggest you to open a support call with us through http://support.microsoft.com: if you are based in EMEA I'll be happy to work with you on the problem, otherwise one of my colleagues from US or India will take your call.

    HTH

  • Jakie
    29 Jun 2007 7:43 PM

    This blog saved my day! Thanks

  • Andy Brudtkuhl
    20 Jul 2007 5:28 PM

    I've found that doing a "rebuild" and try to publish again and that did the trick. Of course I tried everything I've read about before that to no avail. So it could be a combination of things...

    Who knows... but it works now!

  • Ray Gudgeon
    9 Oct 2007 4:13 AM

    You might be interested to know that this same error comes up if you name a dataset (inApp_Code) with the same name as one of your pages.

    I had a reporting application and named the dataset for the report with the same name as the page that serves the localreport. Everything works fine in VS2005 but the error manifests when you publish the app.

    Seems weird to me...

    I guess a good naming system is the answer so such items cannot accidently get the same type names without one knowing it.

    Regards

    Ray

  • Carlo Cardella
    9 Oct 2007 5:46 AM

    Thanks Ray; the principle behind it is the same, the dataset and the page will be compiled in two separate classes with the same name, hence we have the problem.

    To be honest I'm not sure why the problem does not repro within Visual Studio, but I guess the point is that this error happens only when we publish (precompile) the site but it works fine when the whole code is compiled on the fly; since within Visual Studio we're not precompiling... we don't get the error

  • DBuckner
    29 Dec 2007 5:32 PM

    This can also happen in control library's if you are linking to a common(shared) file in 2 or more assembly's. It pops up when the controls are referenced in the ascx through the register directive.

    HTH's,

    Dave

  • Winstone Jordaan
    12 Jan 2008 8:02 AM

    Thanks, good post, on the nose, to the point, just the way I like them.  Saved me much downtime...

  • Jon
    29 Feb 2008 1:38 PM

    This was a great post to find, helped me get to the bottom of things very quickly.  Thanks

  • Rujith
    10 Apr 2008 9:08 AM

    Very useful blog...

    Because this works in JIT mode and doesnt work in precompiled mode, we will never think that its problem with the using the same type. Eventhough the error message says that still we will not look in that direction.

    Really useful blog, to the point and saved lot of my time. Thanks

  • Mark Taylor
    2 May 2008 2:24 PM

    I just ran into this same problem with an application that I converted from .NET 1.1 to .NET 2.0.  I followed the suggestion of Andy Brudtkuhl and rebuilt to project, I then published and it's now working fine.

    Thanks for the timesaver!

  • Sarbjit
    29 Jul 2008 8:36 AM

    It is really very good post. it helps me alot while  resolving problems

  • Sreenath Medikurthi
    12 Aug 2008 4:19 PM

    Hi,

        The easy solution for this problem is create the new web page(aspx) and copy the design and code from where you this problem to new page.And publish then run then you wont the problem

  • pchin
    4 Sep 2008 2:25 PM

    I have the same problem. I think that's because one of my control name and the tag name is same. Now I have changed the tag name. Hope this will resolve my problem.

    This post has helped me a lot.

  • pchin
    5 Sep 2008 11:37 AM

    I take my statement back, because this morning again I have the same problem, please help me

Page 1 of 3 (36 items) 123
  • © 2012 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy Statement
  • Report Abuse
  • 5.6.131.143