Last post Dec 27, 2011 08:59 PM by Sonic Go - MSFT
Dec 19, 2011 03:02 AM|ronit_rc|LINK
I have written a Http Handler for File uploading purpose. In the .ashx file, I want to use an existing class library (written by myself). I have added Reference to the Class Library in the project. But still I cannot use it in .ashx file code. I can use
the Class Library in other .aspx.cs file code without error on just "using" it. I am doubting something. Is that so, we can use class librarires in .ASHX handlers, only when they are placed in GAC? I am using the Class Library as a private assembly.
Please help me .
Dec 19, 2011 03:35 AM|anurajp|LINK
I think there is no restriction like that. Are you getting any errors / exceptions?
Dec 19, 2011 08:29 AM|ronit_rc|LINK
Yes, I am experriencing a "Type or Namespace not found" kind of error wheaeas I can access the dll from a .aspc.cs file on the same directory.
Dec 23, 2011 07:56 AM|Sonic Go - MSFT|LINK
An ASP.NET HTTP handler is the process (frequently referred to as the "endpoint") that runs in response to a request made to an ASP.NET Web application. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an
.aspx file, the request is processed by the page via the page handler. If you checking the .aspx page inheritance relationship, you will find it inherit from IHttpHandler, such as .ashx.
public class Page : TemplateControl, IHttpHandler
If you could using existing class library in aspx, you can do it in ashx too. there is not restriction.
for more information about IHttpHandler, please refer to
About the issue of GAC. It's not make a sense. If it works as GAC, it should work as private library. There is something different of GAC and private library.
The one is how to load them into domain. As you know, CLR process should have 3 app domain, System Domain, Share Domain and Default Domain, and you can new app domain. GAC will load into the Share Domain. So, other app domains could use them but not need
to reload them again. The private libary must load into every app domain, if they have not loaded.
The other is week name & strong name.
The CLR supports two kinds of assemblies: weakly named assemblies and strongly named assemblies.
Weakly named assemblies and strongly named assemblies are structurally identical—that is, they use the same portable executable (PE) file format, PE32(+) header, CLR header, metadata, manifest tables, and IL.
The real difference between weakly named and strongly named assemblies is that a strongly named assembly is signed with a publisher’s public/private key pair that uniquely identifies the assembly’s publisher. This key pair allows the assembly to be uniquely
identified, secured, and versioned, and it allows the assembly to be deployed anywhere on the user’s machine or even on the Internet. This ability to uniquely identify an assembly allows the CLR to enforce certain known-to-be-safe policies when an application
tries to bind to a strongly named assembly.
for more informatin about GAC, you could refer to
And you can read the book, , Chapter 3 Shared Assemblies and Strongly Named Assemblies, CLR via C#, Jeffry Richter
Dec 26, 2011 01:21 AM|ronit_rc|LINK
Thanks for your help! I forgot to mention one thing, I am adding reference to COM dll developed in Visual Basic. It might causing problem due to this. Any idea?
Thanks in advance.
Dec 27, 2011 08:59 PM|Sonic Go - MSFT|LINK
When the first request is made for an ASPX page the following steps must occur before any code within the ASPX page can execute. IHttpHandler is the same as aspx page.
1.) Source code for a class is generated based on the ASPX page
2.) The source code is compiled to produce an assembly
It is the compiler in step #2 that is returning the error. The compilation of the ASPX page is failing because the source code uses a namespace or type that cannot be located.
The missing reference can be verified by clicking on the "Show Detailed Compiler Output" link in the error message. The assembly reference (set with the /R option) will not appear on the command line passed to the compiler.
In order to resolve the type or namespace, a reference to the assembly that it is defined in must be passed to the compiler. Certain assemblies will always automatically be referenced during the compilation of an ASPX page. These assemblies are defined in machine.config
- All assemblies located in the <WebApplication>/bin
There are several ways to have an assembly be referenced. If the assembly is in the Global Assembly Cache (GAC) it is considered a "shared assembly", otherwise it is a "private assembly". A private assembly is referenced differently than a shared one.
For a private assembly to be referenced when an ASPX page is complied, simply copy in the <WebApplication>/bin directory. This will occur automatically if a reference to it is set in a Visual Studio web project.
An explicit reference must be set to a shared assembly. A shared assembly is uniquely identified by its strong-name and must be referenced with its fully
qualified name which will include its display name, version, culture, and public key token. This information can be determined by browsing to the %WINDIR%\assembly directory in Windows Explorer. Examples of fully qualified assembly names can be seen in machine.config.
There are several ways to reference a shared assembly:
1.) Add a Reference in web.config
Any reference added to the web.config will apply to all ASPX pages in the ASP.NET application. Because this is the case, the web.config is the ideal place to add a reference. A reference is added using the <assemblies> configuration element. For example, the
System.DirectoryServices assembly can be referenced this way:
More information about the <assemblies> configuration element is here:
2.) @ Assembly Page Directive
Any reference set using the @ Assembly page directly will only affect a single ASPX page. The syntax for the directive is:
<%@ Assembly Name="<AssemblyName>" %>
Where <AssemblyName> is the full name of the assembly. For example, the System.DirectoryServices assembly can be referenced this way:
Name=" System.DirectoryServices, Version=1.0.3300.0, Culture=neutral,
More information about this directive is here:
3.) Add a Reference in machine.config
A reference can be added to machine.config the same way it is added to web.config. Any reference set here will affect all ASP.NET applications on the machine.
More information on configuration files is here: