views:

265

answers:

1

I have a HttpHandler called Handler that I compile into a DLL and put in the /bin folder of my ASP.NET app. Then I have a .ashx file:

<% @ webhandler language="C#" class="Handler" %>

but I get a cannot create type 'Handler' error.

However, if I wrap Handler in a gratuitous namespace, say foo, and change the .ashx to

<% @ webhandler language="C#" class="foo.Handler" %>

it works fine. Why can't I use no namespace, er, the default namespace? Microsoft omits a namespace in many examples of HttpHandlers on the msdn website.

+3  A: 

Thi is because of the nature of .Net Assemblies. Any Reference Type or ValueType must be wrapped around a namespace. Namespaces are used for logical grouping. In your case, your class 'Handler' is user-defined reference type. Any assembly can have one or many root namespaces at the root but it can not have a reference type or a value type at the root. In fact when you create a New Class Library Project in the Applications Tab of the Project Properties, it has an option to Specify the Default NameSpace for your Class Library Project. So whenever you create a New Class in your Project it will wrap it around this Default NameSpace specified in the ProjectProperties.Application.DefaultNameSpace.

If you wish to see this in action then try opening your .Net Assembly with IL Disassemblar that comes with .Net SDK.

this. __curious_geek