Global.asax parse error after minor change and revert to previous version

43,510

Solution 1

Cleaning the solution and deleting the assemblies made no difference to subsequent builds. My solution was to just change the output path in project settings for the web app to Bin (rather than bin/x86/Debug).

Source:- "Could not load type [Namespace].Global" causing me grief

Solution 2

we had a similar issue here.

and what we did was just to close the IDE. and open it again, and then build, then run.

pretty frustrating and confusing.

Solution 3

Regular ASP.NET Web Application has 2 files in solution folder:

  1. Global.asax
  2. Global.asax.cs

Make sure that class in Global.asax.cs:

namespace YourWebAppNamespace
{
  public class MvcApplication : HttpApplication
  {
     ...

Has the same/right name in Global.asax:

<%@ Application Codebehind="Global.asax.cs" Inherits="YourWebAppNamespace.MvcApplication" Language="C#" %>

I got an issue with this when I manually changed class name in Global.asax.cs file, so as for result I had the same error as you and from my perspective, it should be more informative. I know that this question already was answered, but maybe my case can be helpful for someone.

Solution 4

  • using Notepad, edit your Global.asax file to make sure it inherits from your web app's namespace

  • check the project properties for its assembly name and default namespace

  • delete your old assemblies from the bin directory (old project assemblies can cause problems!)

    good luck!

Share:
43,510
Raheel Khan
Author by

Raheel Khan

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. - Brian Kernighan

Updated on March 22, 2020

Comments

  • Raheel Khan
    Raheel Khan over 4 years

    The project in context is:

    • ASP .NET Web Application
    • .NET Framework: 4
    • Platform Target: x86
    • IDE: Visual Studio 2010 Ultimate SP1
    • Multiple projects in solution with ASP .NET being the startup project.

    It has been in production for months without glitches until yesterday. I cleaned up the [Global.asax] file (removed unused using statements, refactored, etc.), ran the solution and got the following 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 'CloudTech.ATS.WebClient.Global'.
    Source File: /global.asax Line: 1
    Source Error: Line 1: <%@ Application CodeBehind="Global.asax.cs" Inherits="CloudTech.ATS.WebClient.Global" Language="C#" %>

    Error snapshot

    Here is the Global.asax Markup:

    <%@ Application CodeBehind="Global.asax.cs" Inherits="CloudTech.ATS.WebClient.Global" Language="C#" %>
    

    Here is the Global.asax.cs Code (with internal code removed):

    using System;
    using System.Linq;
    
    namespace CloudTech.ATS.WebClient
    {
        public class Global: System.Web.HttpApplication
        {
        }
    }
    

    After wrestling with this error for a while, I searched, restarted my computer, performed a full clean on the solution, force rebuilt but with no avail. Frustrated, I finally changed only the web application target to "Any CPU" and it worked. Unfortunately, "Any CPU" is not an option or a solution to the issue at hand. Changing it back to "x86" brings the same error back. This happened once and since then, no combination of target platform or debug/release configuration works anymore (same error).

    Furthermore:

    • My development machines are all x64.
    • Checked in the solution, had multiple colleagues test on their machines (both x86 and x64) with the same result.
    • Restored the entire project to a clean state from 3 days ago and the error still persists!
    • Verified tat absolutely NO changes were made to the Web.config files, or any other files in the solution for that matter.

    Lastly, the only change to my development systems has been windows updates (regular security updates) and I have tried the solution on systems without updates with the same results.

    Any help would be appreciated.

  • Raheel Khan
    Raheel Khan about 11 years
    My god, that was #@!@# frustrating. Thank you, Thank you, Thank you! I'm surprised this behavior has not been fixed in SP1 for web projects.
  • Raheel Khan
    Raheel Khan over 10 years
    In my case restarting the IDE did not help for some reason.
  • AceMark
    AceMark over 10 years
    what we did is clean, re-build, close IDE, open IDE and run.
  • Matt
    Matt over 8 years
    although poorly written up this is actually the correct solution to the problem I had. This had a downvote and I upvoted it. The global.asax apparently must sit in the same namespace as web project. i had modified my web projects namespace and the global.asax was using a slightly different one creating this error. Make sure they are in sync is essentially what this answer is saying.
  • AceMark
    AceMark over 7 years
    @kame, which version are you using? could be a different approach per IDE, as they have been updating per version/IDE.
  • James Pusateri
    James Pusateri over 6 years
    I prefer to keep it in a debug folder, but in some cases changing it to bin then back to bin\debug works. Just run it in between. Its the path change that seems to shake the IDE/IIS combo out of that funk.