Introduction
Sometimes, we might get the following error when we try to access a Service.svc after creating the Web or WCF project with Visual Studio.
Could Not Load Type 'System.ServiceModel.Activation.HttpModule'
From Assembly 'System.ServiceModel, Version=3.0.0.0,
Culture=neutral, Publickeytoken=b77a5c561934e089'.
The reason, when there are multiple versions of .NET framework on the computer where IIS is running, and IIS was configured after installing .NET Framework 4.0 or before registering the Service Model in Windows Communication Foundation.
Resolution
In order to fix this issue, we need to register the correct version of ASP.NET with ASP.NET IIS Registration Tool(aspnet_regiis.exe).
Please do the steps as below:
- Open the command prompt with elevated rights (Run as Administrator).
- Change the directory to %WINDIR%\Microsoft.NET\Framework\v4.0.30319 or %WINDIR%\Microsoft.NET\Framework64\v4.0.30319
- Type the following command, then press enter.
aspnet_regiis.exe -iru
Console output:
Microsoft (R) ASP.NET RegIIS version 4.0.30319.17929
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.17929).
...
Finished installing ASP.NET (4.0.30319.17929).
Basically, the above command registers the current version of ASP.NET on IIS and it will not force the IIS to use the current version if there is any other ASP.NET version application already running.
- After getting the finished message from the above command, use the following command to restart the IIS.
iisreset

- Go back to Visual Studio and try to run the project, now it will work as we expected.