Monday, October 1, 2007

Error: The name '___' does not exist in the current context

Recently I got the following error "The name '___' does not exist in the current context" where '___' was the member variable of one of my controls.  I was really confused because even though it was a recently add control I was sure that I was doing it right.  So what else could be the problem?  Well it turns out that I had made a backup copy of the file in the same directory before I had changed it.  I turns out that in a Asp.Net 2.0 website you can't have two ASP.NET pages or user controls with the same name class name.  Because the pages are partial classes it does not give the error "The namespace '<global namespace>' already contains a definition for '_____'" like you would normally get if you redefined a class.  However it seemed that it only use one of the markup files to build the markup's partial class (or it could be that the second backup markup file overwrote the class for the first markup file).  Because it was using the markup partial class from the backup file and the new variable did not exist in that file I got the undefined variable error.  Also unlike ASP.NET 1.1 and 2.0 Web Application projects you can't have two classes with the same CodeFile.  Although it is not an error in a dynamically complied ASP.NET 2.0 website it is an HttpCompileException error in a precompiled ASP.NET website.  The ASP.NET 1.1 Installation Project also had problems with what it considered duplicate files where the main website's project would compile fine but when generating a msi installation package it would complain about the duplicate files.