14
votes

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}");
    }
}

}

23
Anything more explicit in event viewer ?Florian F.
Can you show your Global.asax.cs codemalkam
is it exact code of file??Ehsan Sajjad

23 Answers

33
votes

Solved, just renamed the Global.asax or delete it fixed the problem :/

Other known related bugs I found on the web:

  1. Global.asax.cs: must inherit from HttpApplication -> public class MvcApplication : HttpApplication
  2. Project output must be the bin folder and not Bin/Debug, etc.
  3. Iss application pool is not in the correct .net version.
8
votes

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#" %>

5
votes

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

2
votes

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

2
votes

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.

1
votes

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.

1
votes

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.

0
votes

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

0
votes

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.

0
votes

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

0
votes

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!

0
votes

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#" %>
0
votes

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#" %>
0
votes

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

0
votes

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

0
votes

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
0
votes

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

0
votes

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.

0
votes

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

0
votes

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.

0
votes

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

0
votes

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.

0
votes

Check your imported References the Target framework version. In my case, I add a reference that was not the same Target framework.