views:

313

answers:

5

In my .Net 2.0 Asp.net WebForms app, I have my Global.asax containing the following code:

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

However when I build I get an error stating-

Could not load type 'MyNamespace.Global'.

This seems to be because the MyNamespace namespace (defined in the code behind file Global.asax.cs) is not seen by the compiler in the Global.asax file (does not show in R# intellisence..). This turned out to be a very hard nut to crack... any help will be appreciated!

Note: The Global.asax and the Global.asax.cs are located in the same folder.

Note2: When compiling from the vs prompt with csc it compiles o.k.

A: 

Have you changed the namespace of your project? I've seen this happen occasionally where I've changed the namespace in the Project Properties dialog but Visual Studio hasn't changed the namespace declaration in existing code files.

PhilPursglove
What do you think i should do?
gkdm
Check the namespace in your .cs file and make sure it's the same as the one declared in the asax file. My suspicion is they'll be different...
PhilPursglove
They are the same..
gkdm
I'm not sure then. All I can suggest for right now is to rebuild and check the contents of namespaces in your assembly with ILDASM.
PhilPursglove
+1  A: 

Check the Build Action of Global.asax.cs. It should be set to Compile.

In Solution Explorer, Right-click Global.asax.cs and go to Properties. In the Properties pane, set the Build Action (while not debugging).

It seems that VS 2008 does not always add the .asax(.cs) files correctly by default.

apollodude217
A: 

I'm having this same issue. Any luck with any of these solutions?

It seems to be able to 'find' the Global.asax.cs file when I put that file in App_Code. But, that sets up all sorts of reference issues and doesn't actually solve anything.

The build works fine for my developer (I'm trying to do HTML/Javascript changes). But, when I check the files out to my machine, they won't build.

C. Togar
Eventualy I moved the code to a script tag instead of a code-behind file. Perhaps a bug with VS.
gkdm
A: 

Having a similar issue except that I can compile fine, when I run, the namespace specified in the global.asax file can not be found. :(

Jack
+1  A: 

I am new to asp .net developement and I faced the similar problem and just now I updated the class as a partial class and worked fine.

public partial class Global : System.Web.HttpApplication

Best of luck :)

sri