16

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

}

Community
  • 1
  • 1
omri
  • 595
  • 1
  • 5
  • 13

25 Answers25

38

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.
alexandre-rousseau
  • 2,321
  • 26
  • 33
omri
  • 595
  • 1
  • 5
  • 13
9

You can change it by editing Global.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" Inherits="YourAppName.MvcApplication" Language="C#" %>

Majedur
  • 3,074
  • 1
  • 30
  • 43
intox
  • 514
  • 7
  • 14
  • My issue was the namespace in the global.asax.cs file was "main_site", but the global.asax file (edited in text editor) needed to be "main_site.Global" – Vinnie Amir Nov 23 '22 at 22:32
6

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

Pradeep Gokul
  • 71
  • 1
  • 2
  • This is closer to why I think the answer is correct. I just published and looks like the debug files I had been using previously had been cleaned for the release compile and publish. Error was fixed once I recompiled as debug mode, as that is where my local website was running from. – ransems Mar 12 '18 at 09:49
2

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

Community
  • 1
  • 1
Mahesh
  • 3,727
  • 1
  • 39
  • 49
2

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.

WSK
  • 5,949
  • 8
  • 49
  • 74
2

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.

Asif Raza
  • 971
  • 6
  • 14
1

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

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

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

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.

Developer Thing
  • 2,704
  • 3
  • 21
  • 26
0

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

Conor
  • 721
  • 1
  • 6
  • 18
0

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!

Hamed Mahdizadeh
  • 936
  • 1
  • 15
  • 29
0

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#" %>
Ali Akbarpour
  • 958
  • 2
  • 18
  • 35
babidi
  • 506
  • 5
  • 6
0

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

letsintegreat
  • 3,328
  • 4
  • 18
  • 39
nl Abdul
  • 1
  • 1
0

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

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • 2
    Welcome to SO! It would be nice to mention what exactly this does, in particular if it has any potential side effects. – Ott Toomet Mar 21 '19 at 18:28
0

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
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
0

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

dolly_do
  • 97
  • 3
  • 3
  • 15
0

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.

Joao Ricardo
  • 311
  • 3
  • 6
0

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

Can Arda Aydin
  • 204
  • 2
  • 13
  • Welcome to SO. Since this answer was already provided, please update the corresponding one, rather than adding a new answer that does not bring any information over it – xiawi Jul 11 '19 at 14:40
  • VS2019.. This didn't work for me, it just complained it couldn't find the file when I restarted VS. Are you missing steps in your solution? – eaglei22 Mar 30 '20 at 16:41
0

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

4b0
  • 21,981
  • 30
  • 95
  • 142
Rams
  • 21
  • 3
0

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

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

niek tuytel
  • 899
  • 7
  • 18
0

Had the same issue, Unload and reload project. Make sure The Global.asax is included in the project

0

for the above error i deleted the global.asax file then restarted visual studio.

guest1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 31 '21 at 05:53
-1

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#" %>
Jesse
  • 3,522
  • 6
  • 25
  • 40