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

3

9

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

Escapism answered 6/1, 2011 at 21:27 Comment(1)
I'm running into this exact problem too, and cannot find a way around it. Can you share your handler you're using for *.svc in web.config? I assume you're running IIS7 in integrated mode?Bettinabettine
P
11

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

Polygenesis answered 8/11, 2011 at 17:25 Comment(0)
E
8

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.

Escapism answered 6/1, 2011 at 22:37 Comment(1)
Thanks! For simplicity of managing versions across servers, I just changed my .NET 4.0 web app's Web.config to say <remove name="svc-Integrated" /> in the <modules> section, and that did the same job.Underset
B
7

There is one more way if all of above doesn't work. (Strange)

We were using Windows Server 2008 R2 SP1 with IIS 7.5.7600

After registering latest framework as given in above answer,

You need to the add handler mapping to v.4.0 assembly manually to web.config and remove "ServiceModel" from Modules.

    <system.webServer>
        <handlers>
            <remove name="svc-Integrated" />
            <add name=".svc" verb="*" path="*.svc" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, 
System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </handlers>
        <modules>
            <remove name="ServiceModel" />
        </modules>
    </system.webServer>

More here

Biblio answered 5/7, 2016 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.