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
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:
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.
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
Other solutions I have tried, which didn't work.
Cleaning/Rebuilding
Cleaning bin, obj folders
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
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.
Source: Stackoverflow.com