Reputation: 1109
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!
Upvotes: 0
Views: 650
Reputation: 28608
You don't need to specify CodeBehind when the code file is in App_Code, try this:
<%@ Application Inherits="BaseGlobal.GlobalAsax" %>
Upvotes: 0
Reputation: 914
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"
Upvotes: 0
Reputation: 6698
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?
Upvotes: 2
Reputation: 3150
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.
Upvotes: 0
Reputation: 795
Try using a relative file path instead of a url for the codebehind attribute. Like App_Code\GlobalAsax.cs
Upvotes: 0