ASP.net error: Mismatch between code file and inherit attribute - c#

Opening a page in Enterprise Portal results in an error shown in Windows-Event-Log:
MyControl.ascx.cs(15): error 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).
Line 15 is marked with (X) in the source below.
ASCX.CS file:
namespace Company.Productgroup
{
(X) public partial class Productname : System.Web.UI.UserControl
{
...
}
}
ASCX file:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Productname.ascx.cs" Inherits="Company.Productgroup.Productname" %>
ASCX.designer.cs file:
namespace Company.Productgroup {
public partial class Productname : System.Web.UI.UserControl
{
...
}
}
What I tried:
Changing the atribute CodeBehind to CodeFile and vice versa
Removing Namespace from ASCX.cs Removing Namespace from
ASCX.designer.cs Changing Inherits attribute in ASCX file to
Productname / Productgroup.Productname
Searched Google / SO for a solution. In nearly every result, the
problem was a non-match between Inherit-attribute and
namepace/classname, eg: Link1, Link2, Link3
What is fact:
All files are stored in the same directory, so no paths-problems
should occur.
Default namespace in VS project is set to Company.Productgroup

Your designer file seems to be the problem. In it the class name is Product while in the other two files it is Productname. It's a little odd that it would be out of sync because the designer file is generated but I have seen it happen. Try fixing it manually and see what happens.
UPDATE
Based on your comments I decided to take a look at some of our ASCXs to see what might be different. In none of ours did the designer file show the inheritance chain. For example:
AutoHideField.ascx.cs
namespace Foo
{
public partial class AutoHideField : System.Web.UI.UserControl
AutoHideField.ascx.designer.cs
namespace Foo
{
public partial class AutoHideField
AutoHideField.ascx
<%# Control ... Inherits="Foo.AutoHideField" %>

Related

" "is not allowed here because it does not extend class 'System.Web.UI.Page'

So I need to develop a web form to get data from the scanner. But I encounter a problem stating that " "is not allowed here because it does not extend class 'System.Web.UI.Page'.
As I'm aware that this topic is already been discussed, I still not able to solve it.
I have tried this steps but none of this working..
Webform not allowed because it does not extend Class
Parser Error: '_Default' is not allowed here because it does not extend class 'System.Web.UI.Page' & MasterType declaration
Webform not allowed because it does not extend Class
and already skim thorugh this https://weblog.west-wind.com/posts/2005/Sep/12/Understanding-Page-Inheritance-in-ASPNET-20 to understand more about the inheritance.
this is the lalala.aspx file
<%# Page Language="C" AutoEventWireup="true" CodeBehind="lalala.aspx.cs" Inherits="TEST.lalala" %>
this is the lalala.aspx.cs file
namespace TEST
{
public partial class lalala : Form
{
//
}
}
I really think that this error is cause by the page inheritance but I don't know how to fix it.. Please someone guide me
Try this (presuming you are not using a master page):
namespace TEST
{
public partial class lalala : System.Web.UI.Page
{
}
}

Why does roslyn throw a RCS1110 warning in ASP.NET C# class files?

We are rebuilding our code structures in VS 2017 from the ground up and our lead has determined that we need to commit all of our code with no compile errors or warnings in Code Analysis. As our old Code base is .net 2.0 that was last updated to .net 3.5 for some minor additions to our sites, we are incorporating tools and features in VS that are new to most of us.
On an ASP.NET Web application, when adding a new aspx page to a project, it auto configures the code behind, sets the Inherits value in the markup and creates a public partial class as it always has.
public partial class webforms_divTableTest : System.Web.UI.Page
{
}
<%# Page Language="C#" MasterPageFile="~/MenuMaster.master" AutoEventWireup="true" CodeFile="divTableTest.aspx.cs" Inherits="webforms_divTableTest" %>
As soon as I build the project it throws this warning on every page set:
RCS1110 Declare 'webforms_divTableTest' inside namespace.
This leaves me with a few questions:
Why isn't this set up in the templates in the first place?
What is the point of this on a conventional "all-in-one form" site (e.g not templated or segmented into more files than exist normally with a masterpages site)?
Why does Quick Action fixer add the namespace declaration in a way that breaks all of the code in the C# file?
How should I add/fix the namespace so that my cs code still works when referenced in the aspx file?
Apparently I can do this:
namespace divTableTest
{
public partial class webforms_divTableTest : System.Web.UI.Page
{
}
}
and change my aspx to:
inherits="divTableTest.webforms_divTableTest"
The compiler and Code Analysis are no longer complaining. The rest of my questions still stand.

What is the cause of compilation error in my code

I am running asp.net, C#4.0 application in VS2010. I get the following compilation error:
Server Error in '/' Application.
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.Collections.Generic;
Line 3: using System.Linq;
My page attribute is :
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
EnableEventValidation="false" Inherits="jsPlumb_jsPlumb_Default2" %>
my c#codebehind class:
namespace CompanyDisplay.jsPlumb.jsPlumb.jsPlumb
{
public class jsPlumb_jsPlumb_Default2 : System.Web.UI.Page
{
}
}
i want namespace to present for running some webservice applications.
Try to do this :
add batch=”false” in the compilation tag of your applications web.config file as shown below
compilation debug=”true” batch=”false”
clean solution
delete the temporary files folder in Visual Studio(the folder which it shows in the exception)
do an iisreset and the rebuild my code again
I got the ANSWER ; I should give the inherit attribute as;
inherits="CompanyDisplay.jsPlumb.jsPlumb.jsPlumb.jsPlumb_jsPlumb_Default2"
This error shows up when code-behind class name doesn't match "inherits" attribute on your aspx page. Maybe you tried to rename something?
Furthermore, I've seen this error, when you try to view a new page, but didn't compile the source, so even though your aspx exists, it can't fight the corresponding code-behind class.
Edit:
You have a completely messed up naming conventions, no surprise you're having troubles to match class names properly.
Sorry, but this is just preposterous!
inherits="CompanyDisplay.jsPlumb.jsPlumb.jsPlumb.jsPlumb_jsPlumb_Default2"
Fix your conventions and maybe you find yourself having source files like this:
CodeBehind="Default.aspx.cs" Inherits="MyNamespace.jsPlumb.Default"
Don't do it like jsPlumb.jsPlumb.jsPlumb....That's just a nightmare!

C# Inheritance Issues

Again, I'm fairly new at this sort of thing and perhaps the error message is telling me what it is and I'm simply not understanding, but... This code in anon.cs
namespace cheese.pies.org
{
using System;
using System.IO;
using System.Net;
using System.Web;
using System.Xml;
public class CasLogin : System.Web.UI.Page
{
private const string CasHost = "notimportant";
public static string GetId()
{
}
}
Ends up giving me an error when referenced here:
<% #Page Language="C#" Inherits="CasLogin" CodeFile="CasLogin.cs" %>
<script language="C#" runat="server">
protected void Page_Load(object sender, EventArgs e) {
String directoryId = CasLogin.GetId();
FormsAuthentication.RedirectFromLoginPage(directoryId, false);
}
</script>
The error is on line one and is:
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).
If I change it from
public class CasLogin : System.Web.UI.Page
to
public class CasLogin : Page
I get this error:
Compiler Error Message: CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?)
If I change it from public class CasLogin : System.Web.UI.Page to
public class CasLogin : Page I get this error
You are missing the correct using statement for the Page class (System.Web.UI) thus when you remove the full qualification the compiler can no longer find the Page class.
You should also fully-qualify the class name in the Page directive, i.e. Inherits="cheese.pies.org.CasLogin"
Good
<% #Page Language="C#" Inherits="cheese.pies.org.CasLogin" CodeFile="CasLogin.cs" %>
Bad
<% #Page Language="C#" Inherits="CasLogin" CodeFile="CasLogin.cs" %>
Per your comment regarding a missing partial modifier:
public class CasLogin : System.Web.UI.Page
Should be:
public partial class CasLogin : System.Web.UI.Page
This tells the compiler that the CasLogin class is defined in multiple files (which is the case with web forms; the designer file is separate from the code behind file).
If it still doesn't work, I suggest recreating the page and copying any relevant code into it. Normally Visual Studio handles all of this automatically and this is a non-issue.
I'm pretty sure it should be
<% #Page Language="C#" Inherits="cheese.pies.org.CasLogin" CodeFile="CasLogin.cs" %>
For the other error you can use
using System.Web.UI;
public class CasLogin : Page
Without fully qualifying the class name it doesn't know which Page you're talking about, so you can be explicit when you declare the class or you can use a using statement. The first error is the same issue, it can't see the CasLogin class inside the chees.pies.org namespace
inherits needs to be:
Inherits="cheese.pies.org.CasLogin"
Looking at my own little test project/code, I see a few things noticably different: the "usings" come before the namespace declaration, and the use of partial class for code behind. Also, note that the Inherits has the fully qualified class (includes namespace).
in Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
in Default.aspx.cs
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Data;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{

C# App_Data class not inherited by aspx - inherits attribute question

I have been trying to figure this out for a while now and even though there are plenty of Google results for the error message I receive the solution eludes me. I think that I am doing what I am supposed to be doing.
VS2010, I created a common.cs in App_Data. The content of common.cs are functions which will be used by all pages. As far as I can tell this is the proper way to share code-behind code among multiple pages.
App_Data\common.cs
namespace nprah
{
public class BasePage : System.Web.UI.Page
{
}
{
fish-creek.aspx.cs
namespace nprah
{
public partial class Fishck : BasePage
{
}
}
fish-creek.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="fish-creek.aspx.cs" Inherits="nprah.BasePage" %>
If I understand the Inherits attribute correctly then it does need to contain the NameSpace.ClassName, which mine does. See: http://support.microsoft.com/kb/312311
When I run this code it results in the following output:
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 11: {
Line 12:
Line 13: public partial class Fishck : BasePage
Line 14: {
Line 15:
Visual Studio is not showing any errors during the design. Any guidance you may be able to provide will be much appreciated. Thanks in advance.
In your ASPX it should be
Inherits="nprah.Fishck"
Inherits in your .aspx should be mapping to your code file(.cs)... and from there your codefile will inherit your basepage like you already did.
And also try to validate that : CodeFile="fish-creek.aspx.cs".
Because with the name of the file you supplied it should be : Codefile="fishck.aspx.cs".
Maybe just a typo.

Categories

Resources