无法加载类型模块C#

时间:2017-09-26 10:51:00

标签: c# visual-studio-2015 httpmodule

对于Web应用程序和模块,我是VS的新手,

我正在尝试运行/调试一个http模块,所以我按照这个有用的教程:

https://dotnetcodr.com/2015/07/10/how-to-register-a-custom-http-module-in-your-net-web-application/

我必须在我的示例WebApplication中调试他的测试模块。

现在我在示例WebApplication中链接了我的模块,我编辑了 Web.config 替换它:

  <add name="DescriptiveNameOfModule" type="HttpModuleTestApplication.Modules.TestModule"/>

使用我的模块

  <add name="DescriptiveNameOfModule" type="MyHttpModule11.MyHttpModule"/>

但是当我运行它时,我得到一个包含以下错误的页面:

    [HttpException (0x80004005): Could not load type 'MyHttpModule11.MyHttpModule'.]
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +9972697
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +38

[ConfigurationErrorsException: Could not load type 'MyHttpModule11.MyHttpModule'.]
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +353
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, Boolean checkAptcaBit) +21
   System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement) +39
   System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) +42
   System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +160
   System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1068
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +82
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Could not load type 'MyHttpModule11.MyHttpModule'.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10085804
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

可能是什么原因? 可能是由IIS不同版本引起的?

1 个答案:

答案 0 :(得分:2)

您可能需要包含此类型所在的程序集的名称。例如

<modules>
    <add name="DescriptiveNameOfModule" type="MyHttpModule11.MyHttpModule, AssemblyNameWithoutExtension"/>
</modules>