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 , and since also Support Engineers sometimes need to eat, I accepted .
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)
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:
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
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
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
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
This blog saved my day! Thanks
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!
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
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
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
Thanks, good post, on the nose, to the point, just the way I like them. Saved me much downtime...
This was a great post to find, helped me get to the bottom of things very quickly. Thanks
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
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!
It is really very good post. it helps me alot while resolving problems
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
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.
I take my statement back, because this morning again I have the same problem, please help me