Compiler Error Message: CS0433 in ASP.NET 2.0


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

Comments (40)

  1. Richard says:

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

    Check out http://www.AlpacaDepot.com

    June 15, 2007

  2. 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

  3. Jakie says:

    This blog saved my day! Thanks

  4. 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!

  5. Ray Gudgeon says:

    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

  6. 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

  7. DBuckner says:

    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

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

  9. Jon says:

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

  10. Rujith says:

    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

  11. Mark Taylor says:

    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!

  12. Sarbjit says:

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

  13. Sreenath Medikurthi says:

    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

  14. pchin says:

    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.

  15. pchin says:

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

  16. Hello, if you’ve already tried to follow what’s described in the post with no luck, I really suggest you to raise a support call with CSS: to address this problem we need to have a deep look at the source code and application structure to take into account dynamic compilation etc… not something that can be done through comments on this blog…

    If you are based in EMEA there are chances I’ll be able to work on the case, but in any case consider give MS Support a try

  17. Raghav says:

    DAVE,

    REGARDING TO YOUR POST BELOW. DO YOU HAVE ANY SOLUTION TO THIS PROBLEM? I AM FACING IT ON MY PRODUCTION SERVER. THE ISSUE IS THE REPLICA OF MY PRODUCTION SERVER IS MY TEST SERVER AND THERE IS NO ISSUE.

    I AM LOST I HAVE NO IDEA WHAT SHOULD I DO.

    re: Compiler Error Message: CS0433 in ASP.NET 2.0

    Saturday, December 29, 2007 5:32 PM by DBuckner

    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

  18. Jorge Barrientos says:

    In my case the solution was prety different, I deleted all the objects from the web server, I just leave a test index.aspx page, later I made the deployment from zero, and that’s all that I have done.

    The solution proposed didn’t apply to my case because I have done thousands of deployment and the error appears suddenly without changes in namespaces or page directives.

    I was pretty worry about it, but this simple and not so elegant procedure make me sleep well.

    Thanks

    Jorge

  19. AB says:

    Thanks.

    In my case the precompiled site had App_Code dir. After I renamed the App_Code to something else the site worked fine.

    Usually the runtime will give a warning if the App_Code dir exists but if the the precomilpled*.config file is deleted it does not seem to issue a warning.

  20. Jorge,

    Cleaning the Temporary ASP.NET Files folder is actually the first easy step to try to fix this error, I omitted it only because that is one of the first things people try to do on a faulting machine… 🙂

    It happens that for some reason after a change to the application the runtime does not updates correctly the temporary files and therefore it encounters some "mismatches" and inconsistencies while loading them. At least in my experience this happens quite rarely though, feel free to let me know if that’s not the case

  21. robstoppani says:

    Thanks to AB,

    I follow the suggestion of AB and the site worked fine.

    In my case the only action was renaming the "App_Code" folder in "Code" folder and this solved the problem.

  22. Rob and AB, does the App_Code folder was empty? I’m asking because if you rename it, the ASP.NET runtime will not compile and execute its content, so even if you resolve the problem (because you are eliminating a name conflict) you’ll lose the functionalities you have in there…

    Thanks

  23. Jordi Ferrer (barcelona - spain) says:

    I had a user control and a web page with the same name… but the first time it compiled ok, only when I added a web service the error appeared.. extrange!!

  24. Manish Buhecha says:

    Thanks a lot for this  blog,

    I was stuck in the same problem and suddenly get help from here.

    Thanks again!!

  25. awe says:

    OK, I have the same error, but it occurs only when i have debug enabled in the web.config file. I also have kind of a special configuration. I have one compiled web application containing some user controls. The code behind is compiled into a dll,  which is referenced in another web application that actually uses the controls. The ascx files (without any code behind files) are copied to the running web application.

    This runs just fine when not debugging, but when I turn on debugging in the web.config file, I get an error saying that the _ascx class is defined in two different dlls – both of them in the Temporary ASP.NET Files.

  26. awe says:

    I actually found a sollution to my problem in another blog post here: http://forums.asp.net/p/998851/1312617.aspx

    What did the trick for me was this:

    Turn off batch compilation,by setting <compilation batch="false"> in web.config.

    The sollution in the post was actually to avoid circular references, wich was not the case in my example, but it works for me like this. My problem was that in the debug configuration I had 2 copies of the asmx file, one in each project. Thats why it worked in release, but not in debug, because in release, there is never references to the ascx files that lives in the project I have that actually defines the controls. It only references the copy in the running web application.

  27. Very Thanks, your post was very helpful. I solved my problem by renaming some of the class pages.

  28. Devender Malik says:

    This was a great help following the post , it helped me to find  the cause of things that happened very quickly and saved a lot time.  Thanks

  29. Patrick M-A says:

    Hi There i am still getting the dreaded :

    CS0433: The type ‘AhsayBackup’ exists in both ‘.DLL’ and ‘.dll’   Error… I have been trying to resolve this for a bout two weeks now to no avail obviously. Would it be possible if u could take a look at my project code? , if not who would i be able to contact….As i have trawled most articles on this matter.   my email address is patrick.marshall-andrew@kcom.com

  30. Hello Patrick, I suggest you to open a Support Call with us (see http://support.microsoft.com), either me or my of my colleagues will be more than happy to assist you on this matter. You have several options to open a Support Call, you can use one of the free incidents you get with MSDN Subscription or if you have bought a Microsoft product in a store, or if your Comany has one of the many Support Contracts Microsoft offers (Premier, Partner etc…) or you can even buy a single incident if you wish/need to.

    HTH

  31. Lasse Hummel says:

    Just a quick note: I have had the same problem – the solution was as simple as it was unexpected. For some reason, when looking at the Properties window for my user control .ascx file, in the Build Action field was stated "Content" – I changed that to "None", and everything has gone smoothly since then.

    Hope that this can help others.

    Best regards,

    Lasse

  32. Philip Egan says:

    Legend. Cheers, I tried loads of other solutions before finding this – if only it was at the top of the google search! :o)

  33. Paul says:

    I am getting a similar error with a website that I did not build. However, the problem is intermittent, and is hard to reproduce. The developer is gone now and I need to fix this problem. Is it possible to fix without the source code? And if so, what do I need to do to fix it? Keep in mind that I am not a developer, so while your above post makes a little sense to me- I don't fully understand what to do.

    Compiler Error Message: CS0433: The type 'ASP.web_controls_footer_ascx' exists in both 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesroot251c6d6791ff74ccApp_Web_feh9napg.dll' and 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesroot251c6d6791ff74ccApp_Web_ehlcqfjl.dll'

    Thanks,

    Paul

  34. Paul says:

    I am getting a similar error with a website that I did not build. However, the problem is intermittent, and is hard to reproduce. The developer is gone now and I need to fix this problem. Is it possible to fix without the source code? And if so, what do I need to do to fix it? Keep in mind that I am not a developer, so while your above post makes a little sense to me- I don't fully understand what to do.

    Compiler Error Message: CS0433: The type 'ASP.web_controls_footer_ascx' exists in both 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesroot251c6d6791ff74ccApp_Web_feh9napg.dll' and 'c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesroot251c6d6791ff74ccApp_Web_ehlcqfjl.dll'

    Thanks,

    Paul

  35. ^A^ says:

    You saved my soul. Thx!

  36. Leonardo says:

    Thanks for this post, solved my issue.

  37. Tom Cleeves says:

    Had a similar problem. Reading your blog you said something about making sure the @Page directive contained the property CodeBehind instead of CodeFile, which I had changed earlier. Changing it back to CodeBehind Fixed the issue. Thank you. Tom

  38. lamdongnd says:

    Shut down w3svc and delete everything from c:WindowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesroot

    added

    on Windows 7

    c:Users{username}AppDataLocalTempTemporary ASP.NET Filesroot

  39. Larry Virden says:

    So, we had a variation of this occur recently. Rather than both occurances appear in the framework temporary folder, one reference was in the GAC and the other in the temporary area.

    What is odd is that the applications, web.config, etc. on this machine had not changed for months.

    The error referred, not to a reference in code developed here, but in the AjaxToolkit dll.

    This error appeared thursday morning without warning. The machine had been rebooted 26 or so hours earlier. We were working on a totally separate machine. The applications impacted are all in heavy use daily.

    The server admins have checked and no changes went into the machine between the reboot and the problem.

    The work around for the error was to modified the web.config to redirect references to the desired version of the DLL.

    If the problem is not due to a reboot or update, then what could suddenly trigger a problem like this?

    Thanks!

  40. Lovejinder kaur says:

    am getting the same error but dont understand how to resolve it???? please help…..

Skip to main content