[.net] Parser Error Message: Could not load type 'TestMvcApplication.MvcApplication'

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?

This question is related to .net asp.net-mvc

The answer is


I resolved this by switching my project properties from Web>>Specific port>>55555 to Auto-assign port


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

Make sure all your own referenced dlls have "Copy Local" set to True in the Properties window, unless they are in the GAC. There is no need to do this with framework dlls.


I have also faced the same issue and somehow IIS Express's config file is not pointing to the correct bin directory for the website. So editing the Config file which will be in Documents/IISExpress/config fixed the issue. Just point to the correct physical path in Site tag as shown below.

     <site name="MYWEBSITE" id="4">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="D:\MYWEBSITE" />
            </application>
            <bindings>
                <binding protocol="https" bindingInformation="*:44305:localhost" />
                <binding protocol="http" bindingInformation="*:6689:localhost" />
            </bindings>
        </site>

If Andy Copley's answer worked for you but simply rebuilding the solution doesn't work, then go to Project | Project Dependencies and make sure that the project that has your Global.asax.cs file in it is dependent on all the other non-test projects in the solution.


At Dev Server - Use AnyCPU in Solution Plateform and build again. Please refer this screenshot. AnyCPU


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.


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.


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.


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.


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"


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.


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.


After spend almost 2 hour I resolve this Issue by just delete a line from .csproj file.

   <PlatformTarget>AnyCPU</PlatformTarget>

I was receiving the parser error after right clicking and excluding the global.asax from my Web API 2 solution.

It turns out that rather than just excluding it, you have to right click and delete it.

After deleting I no longer get the parser error.


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!


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

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!


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.


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.


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.


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.


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.


I got this error when trying to add a service reference to a workflow service. And eventually I had to add this to my web.config.

http://blogs.msdn.com/b/rjacobs/archive/2011/12/16/how-to-enable-service-metadata-for-workflow-services.aspx

As you can see, I added it after the Final Entity Framework tag and before the final configuration tag.

</entityFramework>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8006/Sample/Service1.xamlx"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
        contract="ServiceReference1.IService" name="BasicHttpBinding_IService" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

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.


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.


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.


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.


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.


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.


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.


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.


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


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.


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.


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.


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


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.


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.


Examples related to .net

You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to use Bootstrap 4 in ASP.NET Core No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization .net Core 2.0 - Package was restored using .NetFramework 4.6.1 instead of target framework .netCore 2.0. The package may not be fully compatible Update .NET web service to use TLS 1.2 EF Core add-migration Build Failed What is the difference between .NET Core and .NET Standard Class Library project types? Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies Nuget connection attempt failed "Unable to load the service index for source" Token based authentication in Web API without any user interface

Examples related to asp.net-mvc

Using Lato fonts in my css (@font-face) Better solution without exluding fields from Binding Vue.js get selected option on @change You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to send json data in POST request using C# VS 2017 Metadata file '.dll could not be found The default XML namespace of the project must be the MSBuild XML namespace How to create roles in ASP.NET Core and assign them to users? The model item passed into the dictionary is of type .. but this dictionary requires a model item of type How to use npm with ASP.NET Core