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

Rick Strahl
  • 15,839
  • 13
  • 83
  • 121
  • 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? – Mike Christensen Dec 01 '12 at 23:09

3 Answers3

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

Flexo
  • 82,006
  • 22
  • 174
  • 256
Sriwantha Attanayake
  • 6,943
  • 4
  • 37
  • 44
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.

Rick Strahl
  • 15,839
  • 13
  • 83
  • 121
  • Thanks! For simplicity of managing versions across servers, I just changed my .NET 4.0 web app's Web.config to say in the section, and that did the same job. – Scott Stafford May 07 '12 at 21:33
5

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

Amitd
  • 4,691
  • 8
  • 51
  • 82