155

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?

4
  • possible duplicate of Could not load type MvcApplication Commented Mar 17, 2011 at 14:07
  • 15
    Exit Visual Studio & restart fixed it for me. Commented May 3, 2013 at 18:05
  • delete global.asax file and add a new one, and you will be alright.
    – DotNetGeek
    Commented Jul 8, 2013 at 7:51
  • 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
    Commented Sep 21, 2016 at 12:34

39 Answers 39

171

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"

10
  • This was my problem, caused me so much grief because none of the other solutions here worked for me..
    – Zack
    Commented Dec 14, 2011 at 18:07
  • 3
    +1 This was my problem too. The error message and help on this is basically non-existent. Thanks.
    – Noldorin
    Commented Jan 6, 2012 at 11:50
  • 4
    For me, bin\ was giving error, i changed it to bin only. and it worked.
    – Nanu
    Commented May 13, 2013 at 20:42
  • 1
    For me, the problem was that i had accidently select x86 as active platform, and for this configuration the project settings was wrong (Bin\Debug\x86). Changing back to Any CPU fixed the problem. But changing the output path also worked. Commented Jul 11, 2013 at 12:06
  • 13
    So, changing the Output Path from bin\Debug\ to bin removes the error for me. But the real question is: "Why does bin\Debug not work in the first place?" When I build a Debug or Release configuration, I want the files to be generated in the appropriate bin directory.
    – Ellesedil
    Commented Mar 10, 2015 at 20:37
95

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.

6
  • 4
    +1 Me too. And I've tried a number of things, and by "things" I mean "wild guesses". Good answer! Commented Jan 4, 2011 at 15:51
  • In my case I had IIS pointing to an MVC site that hadn't been built before. Doh. Obviously, building it fixed that.
    – Edgar
    Commented Apr 7, 2011 at 8:05
  • 5
    I also got this error when changing the name of the project but forgot to change the namespace that the global.asax.cs was using.
    – Pricey
    Commented Dec 4, 2012 at 20:16
  • 1
    You are a gentleman and a sir, didn't even think of doing a build on it. Thanks!
    – Ben Black
    Commented Aug 21, 2013 at 19:22
  • 2
    In my case my project was not set to build in the Solution Configuration Properties for some reason: i.imgur.com/kp73sGQ.png Commented Nov 6, 2014 at 1:58
24

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.

4
  • Bingo, this is the solution that worked for me as well. Thank you!
    – moshjeier
    Commented Mar 24, 2012 at 20:37
  • Worked for me as well - isn't this a bug?
    – Matt Wilko
    Commented Jul 5, 2012 at 13:41
  • And check if the CheckBox is checked for build Commented Nov 8, 2012 at 16:15
  • If you're ever in Ohio hmu because I'm buying you 10 beers, been looking at different suggestions for over 3 hours Commented May 10, 2017 at 20:05
10

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.

2
  • This was my problem. I had <assemblies><clear/>... to prevent inheriting assembly references from the parent application in a nested IIS application. Commented Feb 21, 2013 at 22:00
  • I never needed this.. than, out of the blue, I ran into this problem in one of my dev machines. Don't know why it started, but this is the only thing that solved it
    – Pascal
    Commented Jun 14, 2017 at 1:39
9

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.

0
9

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!

1
  • I was required to combine this answer with the answer from @brockstaylor below to solve this problem on Umbraco 7.1.6
    – devinbost
    Commented Sep 23, 2014 at 8:50
9

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

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!

1
  • That's a great answer, should be upvoted more - application renaming happens and such errors are annoying!
    – Bartosz
    Commented Jul 25, 2017 at 10:25
7

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

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.

0
4

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.

1
  • I had added an Ajax Toolkit control but hadn't added the reference to the DLL. Thanks for your #2.
    – pixelmeow
    Commented Jan 8, 2015 at 15:48
4

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.

2
  • Not sure, it is a hosted server and according to them ASP .NET MVC working fine. Commented Oct 21, 2009 at 5:12
  • I found another person (with Uncle Google) who experienced a similar error for a different reason. Added link to answer. Good luck! Commented Oct 21, 2009 at 5:15
3

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

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 :)

1
  • that actually did it for me!
    – ra170
    Commented Jul 3, 2015 at 21:38
2

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

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

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

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

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

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
  • Mine too, the solution file has had a few files removed and I didn't realise until I closed and re-opened Visual Studio Commented Nov 29, 2014 at 21:37
1

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

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

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
1
  • Deleted these... and now they don't reappear. Commented Oct 24, 2014 at 6:12
0

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

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

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

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

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

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

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.