Sunday, June 8, 2008

Weird C Sharp Errors I ran into today

So, I just spent a while trying to fix these CS errors:

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cuts_try_3\9354e1fa\4cc0037f\App_Web_drt6meif.2.cs(237,29): error CS0115: 'ASP.savedcharts_aspx.GetTypeHashCode()': no suitable method found to override
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cuts_try_3\9354e1fa\4cc0037f\App_Web_drt6meif.2.cs(242,30): error CS0115: 'ASP.savedcharts_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cuts_try_3\9354e1fa\4cc0037f\App_Web_drt6meif.2.cs(128,18): error CS0535: 'ASP.savedcharts_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable'

After a reasonable amount of time, I realized one of my files is named SavedCharts.aspx

So, whats the problem? When you choose place code in a separate file (aka code behind), .NET auto generates that file for you. Supercool. The problem comes when you rename the newly created file (like renaming default.aspx to, lets say, savedcharts.aspx). Sometimes, the class name in the code behind file does not get changed.

Here is a quick example that would throw these errors:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="CreateNewUT.aspx.cs" <span style="color: rgb(51, 204, 0);">Inherits="CreateNewUT"</span> Title="Untitled Page" %>
<-- insert asp/html page here -->

public partial class<span style="color: rgb(255, 153, 0);"> Default :</span> System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
}


The problem is, I changed my page, and told it to inherit from class CreateNewUT. But, I didnt rename the class in my code behind page. To Fix:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="CreateNewUT.aspx.cs" <span style="color: rgb(51, 204, 0);">Inherits="CreateNewUT"</span> Title="Untitled Page" %>
<-- insert asp/html page here -->

public partial class<span style="color: rgb(255, 153, 0);"> <span style="color: rgb(102, 255, 153);">CreateNewUT :</span></span> System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
}


Hope that helps someone ;) Don't know why VS and/or VWD 2008 seem to correctly rename the class some and not some, but hopefully that gets ironed out soon.

Hamy

No comments: