Solve IIS 8 Error: Could not load type ‘System.ServiceModel.Activation.HttpModule’

本文详细介绍了在使用.NET4.5部署WebSocket服务器应用到Windows Server 2012及IIS8时遇到的错误Could not load type 'System.ServiceModel.Activation.HttpModule'的解决方案。主要涉及了冲突的模块和处理器配置问题,通过删除3.x版本的模块和处理器配置,成功解决了部署问题。

Solve IIS 8 Error: Could not load type ‘System.ServiceModel.Activation.HttpModule’

Zhuyun Dai30 Jun 2013  CPOL
Rate this:  
How to solve "Could not load type 'System.ServiceModel.Activation.HttpModule’ IIS 8 error

Introduction

I encountered an error when I was deploying my WebSocket server application which targeted .NET 4.5 to Windows Server 2012 plus IIS 8. It was an exception shown in browser whenever I tried to open a web page. The exception said:

"Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly
 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'"

When I was working on IIS 7.5, I heard about this problem and knew the cause: the default configuration inapplicationHost.config (in C:\Windows\System32\inetsrv\config) declared two conflicted modules and two conflicted handlers:

<modules>
  <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, 
  System.ServiceModel, Version=3.0.0.0, Culture=neutral, 
  PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
  <add name="ServiceModel-4.0" type="System.ServiceModel.Activation.ServiceHttpModule, 
  System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, 
  PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler,runtimeVersionv4.0" />
</modules>
<handlers>
  <add name="svc-Integrated" path="*.svc" verb="*" 
  type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, 
  Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode" />
  <add name="svc-Integrated-4.0" path="*.svc" verb="*" 
  type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, 
  System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, 
  PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

As we know, applicationHost.config contains the root settings for all web sites and web applications on the server. Therefore, any web application would have all the four conflicted modules and handlers loaded by default. “ServiceModel” and “svc-Integrated” were for .NET Activation 3.x while “ServiceModel-4.0” and “svc-Integrated-4.0” were for .NET Activation 4.x. Unfortunately, the 3.x items were declared before the 4.x items. That was why the exception occurred for a .NET 4.x web application!

Then how did such a situation happen? On Windows Server 2008, it could happen when you install .NET 3.x framework or IIS 7.5 with Activation features after .NET framework 4.x is installed. However, on Windows Server 2012, it always happens when you install .NET framework 3.x with Activation features.

Microsoft officially announced the solution (http://support.microsoft.com/kb/2015129) for Windows Server 2008 plus IIS 7.5: manually running “aspnet_regiis.exe /iru” for .NET framework 4.x (inC:\Windows\Microsoft.NET\Framework\v4.0.30319 or C:\Windows\Microsoft.NET\Framework64\v4.0.30319). However, aspnet_regiis.exe is not allowed to run for IIS 8. I tried manually changing applicationHost.config. I also tried removing and adding features in a good order. But all these solutions did not work.

The final solution was to delete the 3.x module and handler from IIS manager. You could delete them at the application or site level if you want to keep them in applicationHost.config. But I wanted to delete them from applicationHost.config. So I did the following steps:

  1. In IIS manager, click the machine name node.
  2. In “Features View”, double-click “Modules”.
  3. Find “ServiceModel” and remove it.

  4. Go back to the machine name node’s “Features View”, double-click “Handler Mappings”.
  5. Find “svc-Integrated” and remove it.

Now everything works well.

CodeProject

在构建项目时,遇到 `failed to solve: Canceled: context canceled` 错误通常与构建工具的上下文被中断有关。该问题可能由多种原因引发,包括但不限于超时、用户手动取消操作、资源不足或依赖项加载失败。 ### 常见原因及解决方法 #### 1. **超时或长时间未响应** 如果构建过程耗时较长,某些工具(如 Docker BuildKit)可能会因等待时间过长而自动取消上下文。可以通过调整超时设置或优化构建流程来缓解此问题。 - **Docker BuildKit** 中可以尝试增加 `BUILDKIT_STEP_LOG_MAX_WAIT` 环境变量的值以延长等待时间。 - 确保构建过程中所有依赖项都已缓存或本地存在,避免远程资源加载导致延迟。 #### 2. **用户主动取消操作** 如果用户在构建过程中中断了执行(例如按下 `Ctrl+C`),则上下文会被取消。确保在构建期间不要中断操作,并在自动化脚本中避免不必要的中断逻辑。 #### 3. **资源限制** 构建工具可能因系统资源(如内存、CPU)不足而无法继续执行任务,导致上下文被取消。可以通过以下方式排查: - 监控系统资源使用情况。 - 在 Docker 中增加内存限制,例如使用 `--memory` 参数。 - 减少并行构建的任务数量。 #### 4. **依赖项或网络问题** 如果构建依赖项无法下载或访问失败,可能导致构建过程卡住或取消。检查网络连接,确保所有依赖源可用,或使用代理配置。 #### 示例:Docker 构建错误的处理 ```dockerfile # Dockerfile 示例 FROM golang:1.21 WORKDIR /app COPY . . RUN go build -o myapp CMD ["./myapp"] ``` 在构建时,可以使用以下命令尝试增加资源限制: ```bash docker build --memory=4g -t myapp . ``` #### 5. **升级构建工具版本** 某些旧版本的构建工具可能存在上下文管理方面的缺陷。尝试升级 Docker 或其他构建工具至最新版本,以修复潜在的 bug。 #### 6. **检查构建日志** 详细查看构建日志,确认上下文取消发生的具体阶段。日志中通常会包含更详细的错误信息,有助于定位问题根源[^1]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值