[c#] IIs Error: Application Codebehind=“Global.asax.cs” Inherits=“nadeem.MvcApplication”

I am trying to deploy my web project and I keep getting this error:

Line 1: <%@ Application Codebehind=“Global.asax.cs” Inherits=“nadeem.MvcApplication” Language=“C#” %>

I looked at this post: Parser Error: Server Error in '/' Application

But it is currect in my project.

I suspect it something with my iis7 configuration.

Any ideas?

Global.asax:

<%@ Application Codebehind="Global.asax.cs" Inherits="tamal.pelecard.biz.MvcApplication" Language="C#" %>

Global.asax.cs:

namespace TamalTest
{
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

public class MvcApplication : HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    }
}

}

This question is related to c# asp.net asp.net-mvc-3

The answer is


Same issue i faced , when copy the project from another system. In my case i fixed this issue:

delete everythings from inside Bin folder. Clean & Rebuild the app again

Hope this will help.


It may occur due to the clean solution.The dlls in the bin will be removed. 1.Clean Solution 2.Rebuild the solution 3.If the build process have failed,not all the necessary dlls will be stored in the bin. This is another scenario where the error occurs


In my case problem occurred after namespace renaming. I didn't use external tool like Re-sharper, I did renaming manually.

In that process, Views/Web.config file was left unchanged. After replacing old namespace name with the new one in this file, the error disappeared.


I found that this problem happened to me and to a colleague after changing the name of our solution/project.

The issue resulting from my colleague: I pulled changes into my branch and had the error. In my bin folder I found the old .dll files sitting with the newly named .dll files. Deleted the old ones and the problem went away.


In My case the issue was fixed by changing the solution platform from AnyCPU to x86.


Deleting Global.asax and restarting Visual Studio fixed the problem for me.


I faced similar error, tried all the suggestions above, but did not resolve. what worked for me is this:

Right-click your Global.asax file and click View Markup. You will see the attribute Inherits="nadeem.MvcApplication". This means that your Global.asax file is trying to inherit from the type nadeem.MvcApplication.

Now double click your Global.asax file and see what the class name specified in your Global.asax.cs file is. It should look something like this:

namespace nadeem
{

public class MvcApplication: System.Web.HttpApplication
    {
    ....

But if it doesn't look like above, you will receive that error, The value in the Inherits attribute of your Global.asax file must match a type that is derived from System.Web.HttpApplication.

Check below link for more info:

Parser Error: Server Error in '/' Application


Nothing above worked for me. Everything was correct.

Close the Visual Studio and reopen again. This fixed the issue in my case.

The problem could have been caused by different versions of visual studio. I have Visual studio 2017 and 2019. I had opened the project on both the versions simultaneously. This might have created different set of vs files.

Close any instance of the Visual Studio and open again.


I'd a similar problem in WebAPI (related MVC).

I fixed with:

Adding ".Global" to inherits in .asax file (not asax.cs)

Inherits="mynamespace.WebAPI.Global" 

and changing the public class (asax.cs)

public class Global : System.Web.HttpApplication

Problem could occur if you have changed the namespace of your project.

Change the Namespace from Project Properties and also replace all old Namespace with new ones. Renaming to correct namespace might fix the issue.

Source


In my case, I copied the project and pasted it as another project. The Global.asax file contains the wrong file name, so I just change

<%@ Application Codebehind="Global.asax.cs" 
    Inherits="WrongAppname.MvcApplication" Language="C#" %>

to

<%@ Application Codebehind="Global.asax.cs" 
    Inherits="RightAppName.MvcApplication" Language="C#" %>

Make sure the Inherits is pointing to the right namespace of the class because when you create an MVC project under a solution the Inherits value will miss the project name. Therefore you need to fill the gap(project name) manually.

<br><br><%@ Application Codebehind="Global.asax.cs" Inherits="solutionName.projectName.MvcApplication" Language="C#" %>

In my case, it was also caused by old dlls. Clean all your files then rebuild.


I had the same error on IIS Express. In my case, I had two projects as startup projects.I changed properties of the solution to single startup project and ran it. then changed it to previous settings and ran the solution again and no error occurred again!


It's quite weird. Every time I face this issue, have different solution. This time all of the previous fixes failed then I changed project output path from Bin to ..\Build\Bin. It failed. Reverted output path to the previous value , i.e., Bin fixed the issue.


You can change it by editing Globas.asax file (not Global.asax.cs). Find it in app folder in windows explorer then edit

<%@ Application Codebehind="Global.asax.cs" Inherits="YourAppName.Global" Language="C#" %>

to

<%@ Application Codebehind="Global.asax.cs" Inherits="YourAppName.MvcApplication" Language="C#" %>


I had the same error. It is solved by following steps

Go to IIS -> find your site -> right click on the site -> Manage Website -> Advanced Setting -> Check your physical path is correct or not.

If it is wrong, locate the correct path. This will solve issue.


The only solution that worked for me

  1. Run, Type command %Temp% -> Deleting "Temporary ASP.NET Files".

Other solutions I have tried, which didn't work.

  1. Cleaning/Rebuilding

  2. Cleaning bin, obj folders

  3. Changing namespace


Right Click > Open Folder in File Explorer

If you are in the directory, find Global.asax not the Global.asax.cs

Right click on Global.asax file then find Open with

Change Inherits="ProjectNameThatHasError.MvcApplication" to Inherits="YourNamespaceNow.MvcApplication"

You can open it in Notepad, Visual Studio any version, anyways you'll be editing text.


I was also getting this error, I deleted dlls from my debug folder and when I started a new instance for debug I got this error. For me the issue was due to the the build setting, Release was selected in the build type, I just changed it to debug and then application was working fine


In my case my site on IIS was pointing to a different project than the one I was running on visual studio.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to asp.net-mvc-3

Better solution without exluding fields from Binding IIs Error: Application Codebehind=“Global.asax.cs” Inherits=“nadeem.MvcApplication” Can we pass model as a parameter in RedirectToAction? return error message with actionResult Why is this error, 'Sequence contains no elements', happening? Failed to load resource: the server responded with a status of 500 (Internal Server Error) in Bind function 500.19 - Internal Server Error - The requested page cannot be accessed because the related configuration data for the page is invalid String MinLength and MaxLength validation don't work (asp.net mvc) How to set the value of a hidden field from a controller in mvc How to set a CheckBox by default Checked in ASP.Net MVC