2006-12-06

Brief Frustration With Global.asax

It was maddening, I tell you. I like to write C# code in a C# source file, not inline in a script tag. So I went about modifying Global.asax to allow me to do so:

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

I then went about defining a class called "Global" in Global.asax.cs. I added the code I needed and proceeded to build the ASP.NET app in Visual Studio 2005. But I got an error:

Global.asax(1): Build (web): Could not load type 'Global'.

Of course, I was perplexed. Why not? Why couldn't the type be loaded?
I thought for a bit, but then went about doing some more coding. Eventually, I had to address the problem, though. How? On a whim I placed Global.asax.cs in the App_Code ASP.NET folder. Once I did that, I was able to build the app.

»

6 comments:

Anonymous said...

Very helpful. This is what happens when people with no common sense or basic sense of usability write programs.

«/\/\Ø|ö±ò\/»®© said...

Heh. Good one. Thanks for visiting, and for your constructive comment.

Anonymous said...

I had the same problem as you. And you helped me out! Cheers :-) Ignore the idiot who left the other comment

Edddy said...

Thanks for sharing. I have the same problem. It's weird that in the CodeBehind does not reference app_code\global.asax.cs

Anonymous said...

So here I am, four full years later using Visual Studio 2010 and experiencing the same problem. That first a-hole comment was a little unbelievable. I would love to see him put down. So he thinks he knows it all? I'm fuming... BTW, your solution worked for me also. I had to move two different code-behind files to the App_Code folder. (I'm sure this would not have been a problem had I coded everything. But I had to use code that someone else wrote and I am so very appreciative of a solution.) Thanks again.

Bryan said...

Very helpful. Exactly what I needed!