153
votes

I am getting the following error on one of our production servers. Not sure why it is working on the DEV server?

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 'TestMvcApplication.MvcApplication'.

Source Error:

Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="TestMvcApplication.MvcApplication" Language="C#" %>

Source File: /global.asax Line: 1

Not sure if anybody came across this error before and how it was solved, but I have reached the end. Any help would be appreciated.

I also need to mention that this is the published code, so all is compiled. Can there be something wrong with my compiler settings?

30
Exit Visual Studio & restart fixed it for me.RickAndMSFT
delete global.asax file and add a new one, and you will be alright.DotNetGeek
This happened to me when deploying a previously working application. Something in IIS (7) got into a bad state; resetting IIS fixed the problem.BurnsBA

30 Answers

170
votes

None of the other answers worked for me. I fixed my error by changing the web project's output path. I had had it set to bin\debug but the web project doesn't work unless the output path is set to simply "bin"

96
votes

I've had this a couple of times. It's especially frustrating as it's right off the bat, and the error message holds no clue as to what might be the issue.

To fix this, right click your project title, in this case "TestMvcApplication" and click build.

This forces the code to compile before you run it. Don't ask me why, but this has been the solution 100% of the time for me.

24
votes

I have found that when you are forced to use the Configuration Manager to run under x86 or anything other than the standard project "out of the box" settings, the IDE creates a bunch of sub directories under the bin folder for the web project.

Once this starts happening, if the Cassini server is running, then the project does not serve properly.

I fixed it by going into the Web Project properties -> Build settings and changing the Output Path to be bin\

Then rebuild and all works as it should.

10
votes

I tried all above solutions but no luck. Adding line <add assembly="*" /> to web.config fixed it for me. (You can also add to machine.config or root web.config file of the appropriate .NET framework version, I didn't try it) Thanks to MS Support for solution.

9
votes

After a long hard look I came accross the real issue here.

The assemblies were corrupted by the FTP client I used to upload the files to a hosted environmet.

I changed my FTP client and all is working as intended.

9
votes

I had the same problem: mine was because the web project had a platform target of x86. I was running on a 64-bit machine; other projects in the solution were set to 64-bit.

To check your settings, right click the project and choose Properties. On the Build tab, check the value of "Platform Target".

Also check your solution's build configuration (Build menu > Configuration Manager) to check all your projects are being built to the same platform.

In both cases, make sure you check the settings both for debug and release mode - otherwise you'll get it working on your machine but not when you deploy it!

9
votes

I had what looked like the same error. I tried many suggestions from many pages only to find out the problem was that I had the website set to the wrong version of .Net

No matter how many re-compiles or people saying 'configuration problem', nobody made the point that the .net version needed to be checked.

8
votes

IT happens with me when I rename my project/solution. Go to the folder of project in windows explorer (get out of VS). Find and open the file Global (maybe you'll find 2 files, open that dont have ".asax.cs" extension), and edit the line of error with correct path. Good luck!

7
votes

I experienced the exact same problem a couple of days ago - as far as I can tell it was an issue with a 64-bit IIS running a 32-bit web application. We changed our production server to 32-bit and this issue disappeared.

5
votes

Make sure your default namespace in the web project properties is the same as the namespace in the Global.asax.cs. I had modified the default namespace to make it a subnamespace, changing it back fixed this issue for me.

4
votes

For completness sake I included what my issue was and how I solved it:

If your like me and have httphandlers via web.config and you have redirects from your global.asax.cs (maybe in Session_Start() ) like in my case you get this error if your startup project does not have a reference defined which points to the target where your httphandler is pointing!! (but you wont get build errors, just runtime errors)

So:

  1. Double check your web.config for any external items
  2. Double check your startup project has all the references it needs.

Cheers.

4
votes

The only time I have experienced this was when the MVC framework was not installed on the server. Could that be the case?

A missing Pages section in Views\Web.config could also be at fault.

3
votes

I had the same error and none of your solutions helped. I think my problem was simply the name that I had chosen for the project. I had named my project 'interface' which when I got the parse error it said that it couldn't load:

Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="@interface.MvcApplication" Language="C#" %>

Where there was an '@' sign for some reason. I am guessing the word 'interface' is reserved for something else and it added the @ symbol but that obviously broke something. I deleted the project and made a new one with a different name with no problems.

3
votes

Here's another one:

  1. I had been working on a web api project that was using localhost:12345.
  2. I checked out a different branch from source control containing the same project.
  3. I ran the project on the branch and got the error.
  4. I went to "Properties > Web > Project Url" and clicked "Create Virtual Directory"
  5. A dialog came up telling me that the url was mapped to a different directory (the directory for the original project).
  6. I clicked Okay and the virtual directory was remapped.
  7. The error went away.

I hope that helps someone somewhere :)

2
votes

I had a lot of problems and errors to solve, some of the above answers helped, but what the final trick that made it work for me was: Go to your project, click properties.

Go to the Package/Publish Web tab and make sure the configuration is set to Release and Platform to All Platforms.

Last make sure that the "Items to deploy (applies to all deployment methods)" is set to "All files in this project folder"

It then worked fine for me.

2
votes

This issue is complicated because it's easy to confuse the root cause with whatever the immediate cause happens to be.

In my case, the immediate cause was that the solution is configured to use NuGet Package Restore, but the server was not connected to the internet, so NuGet was unable to download the dependencies when building for the first time.

I believe the root cause is simply that the solution is unable to resolve dependencies correctly. It may be an incorrect path configuration, or the wrong version of an assembly, or conflicting assemblies, or a partial deployment. But in all cases, the error is simply saying that it can't find the type specified in global.asax because it can't build it.

2
votes

Make sure that the Namespace in the Global.asax file matches that in the Global.cs file i.e.

Global.asax: Some.Website.Webapplication

Global.cs: Some.Website (minus the 'WebApplication')

2
votes

I tried most of the above answers and they didn't work. For some reason just closing and reopening VS fixed the problem for me.

2
votes

My issue was solved when I converted in IIS the physical folder that was containing the files to an application. Right click > convert to application.

1
votes

For me, it was because I had temporarily excluded the file from the project. I merely included it in back in the project and then it worked.

1
votes

In my case reference of System.Web.MVC was missing from my project. But after adding references issue was same so i checked properties of my Bin folder it was ReadOnly. Just after making it writable,everything working fine.

1
votes

I was getting error because I deployed the application as a virtual directory and I was was getting parser error "could not load type" then I deployed the application as a web site and i was not getting that error again.

0
votes

None of the other answers resolved this error for me.
I did find a solution that worked, which I suggest for those in the same situation:

  1. Close Visual Studio
  2. Browse to Projects\yourProject\yourProject
  3. Rename Web.Debug.config and Web.Release.config
  4. Rebuild and run your application
0
votes

I never really did get to the bottom of what was causing it for me. I think somewhere I must have been missing some files. I got the error after publishing to a new server. Eventually I copied the site from working site. Then the site worked and so did further publishes to the new server.

0
votes

Follow these steps:

  1. Build
  2. Configuration Manager
  3. Put the AnyCPU project
  4. Back to generate
  5. Ready, after this just follow the same steps to pass it to x86 or x64
0
votes

For me, I had a DLL included with my project that had to be run in a 32-bit environment.

The server was configured to run the website in 32-bit mode, but I was not able to run the application on my 64-bit machine because the localhost folder had not been specified to run in 32-bit mode.

0
votes

I just had a similar problem.

The reason was that I was changing a file.aspx.c and had to do a clean rebuild. After that everything worked.

0
votes

My problem was that I was trying to create a ASPX web application in a subfolder of a folder that already had a web.config file, and

So I opened up the parent folder in Visual Studio as a Web Site (Open > Web Site) I was able to add a new item ASPX page that had no issue parsing/loading.

0
votes

For me, the problem was only on certain (long) links within the website and was tracked down to URLScan having the default configuration of a URL length limit of 260.

0
votes

I've had the same issue. Try to:

Right click on the project and select Clean, then right click on it again and select Rebuild and run the project to see if it worked.