Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Avoid Adding Assembly Version In web.config?

I'm adding a custom endpoint behaviour to my WCF service with a class extended from BehaviorExtensionElement to initialise it. In my web.config, I add the following to register the behaviour extension:

<system.serviceModel>
    <services>
      <service name="Service.MyService">
        <endpoint address=""
                  behaviorConfiguration="endpointBehavior"
                  binding="basicHttpBinding"
                  contract="Contracts.IMyService"/>
      </service>
    </services>

    <behaviors>
      <endpointBehaviors>
        <behavior name="endpointBehavior">
          <logBehavior />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <extensions>
      <behaviorExtensions>
        <add name="logBehavior"
             type="MyNamespace.MyBehaviorExtensionElement, MyAssembly, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
</system.serviceModel>

This works absolutely fine, but I have to specify the version of the assembly to get it to load. If I change the assembly reference to just MyNamespace.MyBehaviorExtensionElement, MyAssembly without the version/culture/token then the service fails to launch with the error:

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'logBehavior' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions. Parameter name: element

The final portion of my assembly version will change frequently as part of my build process. How can I avoid having to keep updating the web.config with the new version number every time the build version increments (which could be hundreds of times)?

like image 249
Adam Rodger Avatar asked Oct 22 '22 00:10

Adam Rodger


1 Answers

I think the restriction on fully specified class names has been removed in .net 4 or above. Have you tried:

  <behaviorExtensions>
     <add name="logBehavior"
         type="MyNamespace.MyBehaviorExtensionElement, MyAssembly" />
  </behaviorExtensions>

I might be wrong!

like image 131
Richard Schneider Avatar answered Oct 31 '22 14:10

Richard Schneider