0

I've been having this problem for awhile now. I cannot load the types from the code behind files.

For example:

<%@ Application Codebehind="~/App_Code/GlobalAsax.cs" Inherits="BaseGlobal.GlobalAsax" Language="C#" %>

and here is my c# GlobalAsax.cs file:

namespace BaseGlobal
{
    public class GlobalAsax : System.Web.HttpApplication
    {
        //code in here... 
    }

}

Specific error:

Cannot load type BaseGlobal.GlobalAsax

Why am i getting an error? I've been trying to figure this out. NOTE: this is a website project not a web app.

Thanks guys!

Lilluda 5
  • 1,111
  • 3
  • 18
  • 38
  • try this link http://stackoverflow.com/questions/1598829/parser-error-message-could-not-load-type-testmvcapplication-mvcapplication,i hope it helps you. – Kiran1016 Jan 31 '13 at 15:00

5 Answers5

2

Just from the top of my head...

1) Have you tried adding the Src attribute?

Src="~/App_Code/GlobalAsax.cs"

2) Have you pre-compiled the code-behind class?

3) Are you sure the path is resolved to the correct path? Have you tried using an absolute path to make sure?

John Willemse
  • 6,608
  • 7
  • 31
  • 45
  • how is src difference from the CodeBehindFile attribute – Lilluda 5 Jan 31 '13 at 14:56
  • I suggest you try adding it, not replacing the CodeBehind attribute. I can´t access my resources right now, but I remember having a similar issue years ago which was resolved this way. – John Willemse Jan 31 '13 at 14:59
0

Try using a relative file path instead of a url for the codebehind attribute. Like App_Code\GlobalAsax.cs

Sacrilege
  • 795
  • 9
  • 25
0

In all the work that I've done, the Global.asax doesn't use the codebehind attribute in the Application directive. For the Inherits attribute, make sure you are providing the fully qualified class name (with complete namespace). This is very dependent on what you have set in your Project properties. Look at the "Root namespace" value to see if you need to include something more in the Inherits attribute.

NOTE: The exact name and location of the "Root namespace" field could be different based on the Project type and Visual Studio version that you are using.

TLS
  • 3,090
  • 2
  • 25
  • 33
  • That's good information; however, I cannot look at the settings for 2012 at this time. – TLS Jan 31 '13 at 14:53
0

change the web project's output path. set to bin\debug but the web project doesn't work unless the output path is set to simply "bin"

Kiran1016
  • 914
  • 4
  • 14
0

You don't need to specify CodeBehind when the code file is in App_Code, try this:

<%@ Application Inherits="BaseGlobal.GlobalAsax" %>
Max Toro
  • 28,282
  • 11
  • 76
  • 114