Symptoms

  1. IIS Website with ASP.NET 4.0 displays error:

    Server Error in '/' Application
    ...
    Runtime Error
    
  2. .NET application fails to be executed on Windows Shared Hosting server with the following error message (for local requests to the website):

    Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    
  3. .NET Framework 4.0 (or .NET Framework 4.5) was installed on the server and then an earlier version of the .NET Framework was installed, or you enable .NET 3.0 WCF HTTP Activation.

Cause

According to the Microsoft article:

This issue occurs because the ApplicationHost.config file for Windows Process Activation Service (WAS) has the following section defined, and this section is incompatible with the .NET Framework 4.0:

<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />

This section should be defined as follows:

<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler,runtimeVersionv2.0" />

Note You can find the Applicationhost.config file in the following location:

%windir%\system32\inetsrv\config

Resolution

To resolve the issue, please check resolution from Microsoft Article.

In newer versions of Windows Server aspnet_regiis.exe /iru could return output like:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis.exe /iru

Microsoft (R) ASP.NET RegIIS version 4.0.30319.0
Administration utility to install and uninstall ASP.NET on the local machine.
Copyright (C) Microsoft Corporation.  All rights reserved.
Start installing ASP.NET (4.0.30319.0).
This option is not supported on this version of the operating system.  Administrators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Windows Features On/Off" dialog,  the Server Manager management tool, or the dism.exe command line tool.  For more details please see http://go.microsoft.com/fwlink/?LinkID=216771.

Finished installing ASP.NET (4.0.30319.0).

In such case, please use Server Manager to install HTTP Activation feature under .Net Framework 3.5 component.

Internal content