Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load type 'System.ServiceModel.Activation.HttpHandler' Version conflict with WCF REST

I've run into a problem with WCF REST Service. I get:

Could not load type 'System.ServiceModel.Activation.HttpHandler' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

when running inside of the IIS in an ASP.NET 4.0 AppPool.

The problem seems to occur only if:

  • Running inside of IIS
  • When ASP.NET Comaptibility is enabled

Running in Cassini - no problem it works properly. Running with ASP.NET compatibility off - no problem it works.

It appears that it's some sort of handler version conflict trying to instantiate the wrong version of the handler that in turn tries to load an older version of System.ServiceModel, but I haven't been able to trace this down.

Anybody seen anything like this before and have any ideas how to track this down further?

I've looked in ApplicationHost.config and the master web.config files for System.ServiceModel and HttpHandler references but no luck. There.

+++ Rick ---

like image 850
Rick Strahl Avatar asked Jan 06 '11 21:01

Rick Strahl


2 Answers

fire up your Visual Studio 2010 Command Prompt or browse to "C:\Windows\Microsoft.NET\Framework\ v4.0.30319". And run the following command from the command prompt:

aspnet_regiis.exe -iru

This will register latest .net version. Also make sure your app pool is running latest version of .net

like image 138
Sriwantha Attanayake Avatar answered Oct 23 '22 11:10

Sriwantha Attanayake


So as expected this turned out to be a versioning conflict in the default handler mappings in ApplicationHost.config. Specifically IIS has mappings for ASP.NET 2.0 and ASP.NET 4.0 specific references to the service activation handler (and module) and the 2.0 references weren't restricted by a version specific preCondition.

To fix the above problem I had to change (at the System root in ApplicationHost.config):

<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" />

to:

<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,runtimeVersionv2.0" />

Note the EXPLICIT runtimeVersion2.0. There are additional *.svc maps in the same section for the runtimeVersion4.0 which then fire the appropriate runtimes.

According to Microsoft this situation can arise when some older tools (I'm guessing Azure tools???) are installed that don't register the runtime version properly.

Problem solved.

like image 44
Rick Strahl Avatar answered Oct 23 '22 12:10

Rick Strahl