8

Hey I am getting the following error

Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type '_AddToCart'.

Source Error:

Line 1:  <%@ Page Language="C#" AutoEventWireup="true" Codebehind="AddToCart.aspx.cs" Inherits="_AddToCart" Title="Untitled Page" %>
Line 2:  
Line 3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Source File: /FSAICart/AddToCart.aspx    Line: 1 

Where I do have the matching code behind file which is defined as follows

    using System;
  public partial class _AddToCart : System.Web.UI.Page {

Any Ideas ?

3
  • Make sure the underscore appears everywhere. Commented Jun 2, 2011 at 10:29
  • Generally its a best practice to have same name to both the class and the file.try cleaning the solution and building again. Commented Jun 2, 2011 at 10:31
  • got rid of the underscore but still get error Could not load type 'AddToCart'. <%@ Page Language="C#" AutoEventWireup="True" Codebehind="AddToCart.aspx.cs" Inherits="AddToCart" Title="Untitled Page" %> Commented Jun 2, 2011 at 13:09

2 Answers 2

26

Try changing CodeBehind:

<%@ Page Language="C#"
AutoEventWireup="true"
**Codebehind**="AddToCart.aspx.cs"
Inherits="_AddToCart" Title="Untitled
Page" %>

To CodeFile:

<%@ Page Language="C#"
AutoEventWireup="true"
**CodeFile**="AddToCart.aspx.cs"
Inherits="_AddToCart" Title="Untitled
Page" %>

ASP .NET 1.1 used CodeBehind for compiling code in a separate file. ASP .NET 2.0 introduced the CodeFile syntax for compilation of partial classes.

See here for a more detailed explanation.

Sign up to request clarification or add additional context in comments.

Comments

2

Specify the namespace of the Inherits property of Page directive

Look at codebehind of your page. It looks like:

namespace MyWebSite
{
     public partial class _AddToCart : System.Web.UI.Page 
     {
        //...
     }           
}

So you must change Page directive to:

<%@ Page Language="C#" AutoEventWireup="true" Codebehind="AddToCart.aspx.cs" Inherits="MyWebSite._AddToCart" Title="Untitled Page" %>

1 Comment

Sorry not to sure what you mean there can you give an example i.e here <%@ Page Language="C#" AutoEventWireup="True" Codebehind="AddToCart.aspx.cs" Inherits="AddToCart" Title="Untitled Page" %>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.