I have a simple IHttpModule
namespace System.Web.Extensions.Resource
{
public class MyHttpModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PreSendRequestContent = PreSend_RequestContent;
}
private void PreSend_RequestContent(object sender, EventArgs e)
{
HttpResponse response = ((HttpApplication)sender).Response;
response.AddHeader("MyHttpModule", "Running");
}
}
}
And I installed it to GAC with powershell (No errors at all):
$name = "c:\MyHttpModule.dll";
[System.Reflection.Assembly]::Load('System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a');
$publish = New-Object System.EnterpriseServices.Internal.Publish;
$publish.GacInstall($name);
$type = 'System.Web.Extensions.Resource.MyHttpModule,' [System.Reflection.AssemblyName]::GetAssemblyName($name).FullName;
C:\Windows\System32\inetsrv\Appcmd.exe add module /name:MyHttpModule /type:"$type"
But when I access the IIS site, I got
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'MyHttpModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
So Windows no longer support installation to GAC cache?
EDIT
I've added a strong name and confirmed the assembly is installed to C:\Windows\Microsoft.NET\assembly\GAC_MSIL\MyHttpModule\v4.0_1.0.0.0__4959579d21f18138.
Now IIS has a different error
System.TypeLoadException: Could not load type 'System.Web.Extensions.Resource.MyHttpModule' from assembly 'MyHttpModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4959579d21f18138'.
But from ILSpy I can see this type is available, so what was wrong then?
EDIT again
It suddenly worked, I've seen the header added by the module. Not sure why, but closing it now.
CodePudding user response:
The PublicKeyToken is null, which mean the DLL is not signed with a strong name. You need to sign the Dll and then put it to GAC, please refer the MSDN article here, the article also tells you how to sign it in VS: