156

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. 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. Commented Sep 21, 2016 at 12:34

39 Answers 39

172

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"

Sign up to request clarification or add additional context in comments.

11 Comments

+1 This was my problem too. The error message and help on this is basically non-existent. Thanks.
For me, bin\ was giving error, i changed it to bin only. and it worked.
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.
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.
I was getting this after I renamed my project but forgot to rename the namespace it was in so it could not resolve the type...
|
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 Comments

+1 Me too. And I've tried a number of things, and by "things" I mean "wild guesses". Good answer!
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.
You are a gentleman and a sir, didn't even think of doing a build on it. Thanks!
In my case my project was not set to build in the Solution Configuration Properties for some reason: i.imgur.com/kp73sGQ.png
somehow Global.asax.cs was set to Content instead of compile in my case.
|
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 Comments

Bingo, this is the solution that worked for me as well. Thank you!
Worked for me as well - isn't this a bug?
And check if the CheckBox is checked for build
If you're ever in Ohio hmu because I'm buying you 10 beers, been looking at different suggestions for over 3 hours
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.

3 Comments

This was my problem. I had <assemblies><clear/>... to prevent inheriting assembly references from the parent application in a nested IIS application.
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
Sadly that line did not work for me. Where did you put it in the web.config?? It caused errors into the first 2 locations in the web.config that I tried, it caused no additional errors in the 3rd place I tried (inside <runtime>-tags) but it didn't fix the original error :(
10

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.

Comments

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.

Comments

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 Comment

I was required to combine this answer with the answer from @brockstaylor below to solve this problem on Umbraco 7.1.6
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 Comment

That's a great answer, should be upvoted more - application renaming happens and such errors are annoying!
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.

Comments

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.

Comments

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 Comment

I had added an Ajax Toolkit control but hadn't added the reference to the DLL. Thanks for your #2.
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 Comments

Not sure, it is a hosted server and according to them ASP .NET MVC working fine.
I found another person (with Uncle Google) who experienced a similar error for a different reason. Added link to answer. Good luck!
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.

Comments

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 Comment

that actually did it for me!
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.

Comments

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.

Comments

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

Comments

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.

Comments

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.

Comments

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 Comment

Mine too, the solution file has had a few files removed and I didn't realise until I closed and re-opened Visual Studio
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.

Comments

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.

Comments

1

I solved my problem by renaming lots of things. If your problem is cause by creating a new project from copying an existing project like me, you may try these steps.

  1. rename solution - in solution explorer
  2. rename project - in solution explorer
  3. rename namespace - in code
  4. rename assembly name and default namespace - in project>property>application
  5. rename AssemblyTitle and update GUID - in project>property>application>aseembly information
  6. rebuild and run

some of these steps may be worthless, but following them all should solve your problem.

Comments

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 Comment

Deleted these... and now they don't reappear.
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.

Comments

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

Comments

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.

Comments

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.

Comments

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.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.