0

I am getting the following error message.

Any ideas how to resolve this?

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: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

Source Error:

Line 1:  using System;
Line 2:  using System.Data;
Line 3:  using System.Data.SqlClient;
4
  • How about showing us some of the code. In particular, show the class declaration in codebehind, and show us the Page directive in the .aspx file. Commented Jan 17, 2010 at 3:24
  • I am trying to paste the code, but the code is over 600 characters long; so I will try to paste it in two pieces. This is the only code I have written: using System; using System.Data; using System.Data.SqlClient; class SqlConnectionDemo { static void Main() { SqlConnection conn = SqlConnection("Data Source=(local); Initial Catalog=JobSearchManager;Integrated Security = SSPI"); SqlDataReader rdr = null; try { conn.Open(); SqlCommand cmd = new SqlCommand("select * from Agency", conn); Commented Jan 17, 2010 at 3:37
  • rdr = cmd.ExecuteReader; while (rdr.Read()) { Console.WriteLine(rdr[0]); } } finally { if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close; } } } } Commented Jan 17, 2010 at 3:39
  • The aspx page is: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html> Commented Jan 17, 2010 at 3:41

1 Answer 1

2

It's exactly what the error says:

Your .ASPx file Page header has 2 atributes related to your issue: CodeFile and Inherits. The file referenced in the CodeFile attribute must have a class with the same name defined in the Inherits attribute and this class must be a Page or a UserControl.

If this doesn't solve your problem. Let me know.

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

2 Comments

Andre has given you the correct answer, you need to take the time to understand what "CodeFile" and "Inherits" mean in the @Page directive.
Additionally, make sure no other pages (accidentally) try to inherit a class from the same code behind file.

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.