What is the cause of compilation error in my code - c#

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!

Related

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.

ASP.net project parser error?

Zipped up my application for a university assignment and now suddenly it wont work???I Used visual studio to create a class diagram and added assosciations, could this have altered the code?
Below is the error i get when i try launch in browser..
Server Error in '/' Application.
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 'WebApplication4.MvcApplication'.
Source Error:
Line 1: <%# Application Codebehind="Global.asax.cs" Inherits="WebApplication4.MvcApplication" Language="C#" %>
Source File: /global.asax Line: 1
i get this error when i try build my project
Error 2 The type 'WebApplication4.Models.CoreSheetsDBContext' cannot be used as type parameter 'TContext' in the generic type or method 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. There is no implicit reference conversion from 'WebApplication4.Models.CoreSheetsDBContext' to 'System.Data.Entity.DbContext'. G:\Software\Projects\WebApplication4\WebApplication4\Migrations\Configuration.cs 8 27 WebApplication4
// First guess was: Try changing CodeBehind to CodeFile.
Update (question was updated)
(1) A "/" at the end of line 8 is not syntactically correct. (Does it look the same in your code? Would be fine know to the rest of the line including the closing '>',)
... sealed class Configuration : DbMigrationsConfiguration
<WebApplication4.Models.CoreSheetsDBContext/
(2) Let's assume that the ´/´ was just a typo and your code contains a ´>´ instead. DbMigrationsConfiguration has this signature:
public class DbMigrationsConfiguration<TContext>
: DbMigrationsConfiguration where TContext : System.Data.Entity.DbContext
The class CoreSheetsDBContext which you pass as a generic parameter must be a subclass of System.Data.Entity.DbContext. Check that CoreSheetsDBContext actually inherits from System.Data.Entity.DbContext. I.e. it should look like this:
using System.Data.Entity;
public class CoreSheetsDBContext : DbContext { ... }

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.

ASP.NET C# - Source File Parse Error - Could not load inherits type file

How do I fix this error?
I'm running .NET Framework v4.0.30319 so the Framework shouldn't be an issue. I'm not using any DLL files or bin directories. How do I setup the IIS/Virtual Directory if I'm using Forms Authentication for the whole website using VS2010?
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
'ACAWebApplication.Pages.State_Carrier_Search'.
Source Error:
Line 1: <%# Page Title="ACA Web App - State Carrier Search" Language="C#"
MasterPageFile="~/Pages/User.Master" AutoEventWireup="true"
CodeBehind="State_Carrier_Search.aspx.cs"
Inherits="ACAWebApplication.Pages.State_Carrier_Search" %>
Line 2: <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent"
runat="server">
Line 3: <style type="text/css">
Source File: /Pages/State_Carrier_Search.aspx Line: 1
The Codebehind for State_Carrier_Search.aspx.cs file:
namespace ACAWebApplication.Pages
{
public partial class State_Carrier_Search : System.Web.UI.Page
{
protected void Page_LoadS(object sender, EventArgs e)
The code for State_Carrier_Search.aspx file is as follows:
<%# Page Title="ACA Web App - State Carrier Search" Language="C#" MasterPageFile="~/Pages/User.Master" AutoEventWireup="true" CodeBehind="State_Carrier_Search.aspx.cs" Inherits="ACAWebApplication.Pages.State_Carrier_Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
thanks!
Thou shalt not name class and namespace the same
THIS is Your problem
namespace ACAWebApplication.Pages
{
public partial class ACAWebApplication.Pages.State_Carrier_Search : System.Web.UI.Page
{
The parser sees an ACAWebApplication.PAges namespace and sees ACAWebApplication.Pages class name. This is probably legal but it is very wrong
Drop the ACAWebApplication.PAges from the class name and it should work. Was it autogenerated or You have extracted the namespace from the class name. Either way change it
and read
Eric lippert musings on it - whole series quite enlightening
Is the .NET version correctly set in IIS? This could be a .NET 2.0 app trying to run on the 1.0 framework.
Please refer to the Specify a .NET Framework Version for an Application Pool (IIS 7) article to learn more how to specify a .NET Framework version for an application pool.

ASP.NET runtime error : Ambiguous Match found

Recently, my team converted ASP.NET project from .NET 1.1 to .NET 2.0. Everything is pretty good so far except for one web page.
This is the error message I got when I tried to open this page:
Server Error in '/' Application.
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: Ambiguous match
found.
Source Error:
Line 1: <%# Control Language="c#"
AutoEventWireup="false"
Codebehind="Template.ascx.cs"
Inherits="eReq.Web.WebControls.Template.Template"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"
%> Line 2: Line 3:
function
ExpandCollapse_Template(inBtn,
inSection, inSectionID) {
Source File:
/WebControls/Template/Template.ascx
Line: 1
-------------------------------------------------------------------------------- Version Information: Microsoft .NET
Framework Version:2.0.50727.3053;
ASP.NET Version:2.0.50727.3053
I tried renaming class and renaming filename but it didn't work.
Anyone have any idea on this?
It may appeared because of different names of components? for example Button1 and button1, it compiles as casesensitive, but executed as caseinsensitive.
In your ASCX file, go through each and every control and change its id. For example,
<asp:TextBox id="foo" />
change it to
<asp:TextBox id="foo1" >
You've probably got a control with an ID that matches a property in your ascx file, so when the compiler is trying to make instance variables its colliding.
I've the same problem and it solved and the solution is in check your code behind and you will find a couple of Controls with the same name:
protected Button Home;
protected System.Web.UI.HtmlControls.HtmlAnchor home;
you have to erase one line or comment it.
The selected answer seems to be the right one.
In my case i found that im using a variable in the codebehind with the same name as a control in the aspx file, just with different case usage.
I'd trawl your web.config for 1.1 and 2.0 references to the same DLL. In most cases that I have gotten this it was System.Web.Extensions.
Also check the #registers in Pages if that fails.
Good luck (it is not a fun bug to find!)
Dan
Same Name Id in aspx file and property inside aspx.cs file
when .aspx page and behind aspx.cs class contains Same property this kind of problem occur. When I am searching the solution for this problem.. not found any useful content. finally I solved the problem by renaming private property name to different inside aspx.cs class attached image as screenshot.
if anyone still facing the problem you may try
Screenshot 1
Screenshot 2
This is due to what can only be described as a defect in System.Web.UI.Util.GetNonPrivateFieldType(Type classType, String fieldName) that allows UI (.aspx/.ascx) fields to compile as case-insensitive but attempts to retrieve them as case-sensitive during the intial parse.
A potential remedy for the time being is to catch it at compile-time with an ms-build task.

Categories

Resources