How to add HttpHandler located in GAC to IIS7.5

1

I want MyHandler installed in GAC to be applied to all applications hosted on IIS.

I made it work for particular application when I add Managed Handler on global level

<add name="MyHandler" path="*.txt" verb="*" type="MyHandlerAssembly.MyHandler" resourceType="Unspecified" preCondition="integratedMode" />

and .dll to /bin directory of particular apllication. At this point all works as expected excluding that I am not about add this .dll to each apllication.

So I added MyHandlerAssembly to GAC and then I modified type according to gacutil -l MyHandler:

<add name="MyHandler" path="*.txt" verb="*" type="MyHandlerAssembly.MyHandler, MyHandlerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8a3126c79b7aa959" resourceType="Unspecified" preCondition="integratedMode" />

And I receiving error:

System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

With stacktrace:

[FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)]
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +314
   System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +95
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +124
   System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type) +47
   System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +18
   System.Web.Configuration.HandlerFactoryCache..ctor(String type) +27
   System.Web.HttpApplication.GetFactory(String type) +95
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +352
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

What I am doing wrong? Thanks.

UPDATE 1.

Also tried to add my assembly to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config but received error:

Could not load file or assembly 'MyHandlerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8a3126c79b7aa959' or one of its dependencies. The system cannot find the file specified.
iis
httphandler
.net-assembly
gac
asked on Stack Overflow Jun 6, 2013 by Vladimirs • edited Jun 6, 2013 by Vladimirs

1 Answer

1

After adding assembly to GAC for applying changes need to restart IIS. So complete solution is:

  1. Add assembly with module to GAC by executing gacutil.exe -i path_to_project\bin\MyHandlerAssembly.dll
  2. Restart IIS
  3. Add Handler Mapping of type MyHandlerAssembly.MyHandler, MyHandlerAssembly, Version=X.X.X.X, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXX(new types from your assembly will be available after IIS restart)
answered on Stack Overflow Jun 7, 2013 by Vladimirs • edited Jun 7, 2013 by Vladimirs

User contributions licensed under CC BY-SA 3.0