Adding Behavior Extension to PreCompiled Web Site

888 Views Asked by At

I'm trying to add the CORS headers to a WCF service which is part of a precompiled web site project in VS 2012.

The error

The type 'EnableCrossOriginResourceSharingBehavior, MyWebSite, Version=0.0.0.0, Culture=neutral' registered for extension 'crossOriginResourceSharingBehavior' could not be loaded.

from the config file

<behaviors>
  <serviceBehaviors>...</serviceBehaviors>
  <endpointBehaviors>
    <behavior name="jsonBehavior">
      <webHttp />
      <crossOriginResourceSharingBehavior />  <!-- Error Here -->
    </behavior>
  </endpointBehaviors>
</behaviors>
<extensions>
  <behaviorExtensions>
    <add name="crossOriginResourceSharingBehavior" type="EnableCrossOriginResourceSharingBehavior, MyWebSite, Version=0.0.0.0, Culture=neutral" />
  </behaviorExtensions>
</extensions>

Now, there is no MyWebSite.dll in a precompiled site, apparently. So, how do I get past this and make the BehaviorExtension work?

1

There are 1 best solutions below

0
On

You have that error because the definition has a wrong type: you lost namescpace of the type.

<add name="crossOriginResourceSharingBehavior" type="MyWebSite.EnableCrossOriginResourceSharingBehavior, MyWebSite, Version=0.0.0.0, Culture=neutral" />

Probably the version is wrong, because it equals to 0.0.0.0 in the definition. See AssemblyInfo.cs for the assembly version.

I see the assembly hasn't a strong name. So you can remove Version and Culture from the definition.

<add name="crossOriginResourceSharingBehavior" type="MyWebSite.EnableCrossOriginResourceSharingBehavior, MyWebSite" />