We have a lot of web applications, configured using custom sections (in their web.config
) that depend on sectionHandlers
declared in the machine.config
.
As we have several versions of these sectionHandlers
, applications that want to use a new sectionHandlers
have to force "assembly redirection" by using the tag <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
in their web.config
. We can indeed not modify the declaration of the sectionHandlers
in the machine.config
as long as there are still other applications using the oldest version.
The binding redirection works fine for all the assemblies loaded by the applications using the tag mentioned before - except for the assemblies containing types used to define a WCF behavior in the web.config's system.serviceModel
section.
For example, some of our applications are using a custom behavior Extension named mainframeFormatter
(See in the web.config in the example here after). When adding a bindingRedirect
from a version 1.1.0.0 of the assembly containing the type mainframeFormatter
to a version 1.2.0.0, we get the following error:
An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element'mainframeFormatter' cannot be added to this element. Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.
Notice that we only have the problem with the "behaviors" and not with the "bindings". Is this the expected behavior of the Binding Redirection with WCF behaviors or is this a bug ?
Here's a sample of web.config
which fails to be parsed when using binding redirection:
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="mainframeFormatter"
type="Framework.Communication.Mainframe.ClientEndpointBehaviorExtensionElement,
Framework.Communication.Mainframe, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=f510307097254a31"/>
</behaviorExtensions>
<bindingExtensions>
<add name="mainframeBinding"
type="Framework.Communication.Mainframe.BindingCollectionElement,
Framework.Communication.Mainframe, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=f510307097254a31"/>
</bindingExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="ClientEndpointBehavior">
<mainframeFormatter /> <--- Problem is on parsing this with assemblyBinding enabled
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<mainframeBinding>
<binding name="MyCustomBinding"/>
</mainframeBinding>
</bindings>
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Framework.Communication.Mainframe"
publicKeyToken="f510307097254a31" />
<bindingRedirect oldVersion="1.1.0.0" newVersion="1.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I know that changing the version in the behaviorExtension
settings solves the problem. But I am curious why the redirection does not work.
They will provide a hotfix soon.