I'm adding a custom behaviorExtensionElement for WCF and want to add an attribute that can be read when the configured element is being read, e.g.
<system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="myExtension"
             type="Bar.FooBarElement, Bar"/>
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <myExtension myAttribute="Foo" />
However, I get an error "Unrecognized attribute 'myAttribute'. Note that attribute names are case-sensitive."
How can I avoid this? How do I read the myAttribute value in code?
Turns out it's pretty easy, since BehaviorExtensionElement subclasses ConfigurationElement, the usual configuration rules apply.
[ConfigurationProperty("myAttribute")]
public string MyAttribute
{
  get { return (string)this["myAttribute"]; }
  set { this["myAttribute"] = value; }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With