title: Implementing IErrorHandler in a WCF Service Application or a WCF Service Library
body: <p>When implementing the IErrorHandler interfaces and adding it to the dispatcher in a WCF Service <strong>Application</strong> I'm experiencing some strange behavior. 
  Only the <code>HandleError</code> method is fired, not the <code>ProvideFault</code> method.</p>
  
  <p>When using the same code and configuration in a WCF Service <strong>Library</strong> both methods are fired upon an Exception in the code.</p>
  
  <p>Example:</p>
  
  <pre><code>public class ErrorHandler : IErrorHandler, IServiceBehavior
  {
      public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
      {
          // Provide the fault
      }
  
      public bool HandleError(Exception error)
      {
          // If handled return true, otherwise false
      }
  
      // Validate
      // AddBindingParameters
      // ApplyDispatchBehavior
  }
  
  public class ErrorHandlerBehavior : BehaviorExtensionElement
  {
      public override Type BehaviorType
      {
          get { return typeof(ErrorHandler); }
      }
  
      protected override object CreateBehavior()
      {
          return new ErrorHandler();
      }
  }
  </code></pre>
  
  <p>And in the Web.config:</p>
  
  <pre><code>    &lt;extensions&gt;
        &lt;behaviorExtensions&gt;
          &lt;add name="ErrorLogging" type="Service.ErrorHandlerBehavior, Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt;
        &lt;/behaviorExtensions&gt;
      &lt;/extensions&gt;
  ...
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;ErrorLogging /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
  </code></pre>
  
  <p>The code and configuration is the same (although the configuration is in Web.config in the Service Application and i App.config in the Service Library).</p>
  
  <p>By inserting breakpoints in the <code>ProvideFault</code> and <code>HandleError</code> I can see that <code>ProvideFault</code> is only invoked for the Service <strong>Library</strong> - how can this be? Am I missing something?  </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It seems that <code>ProvideFault</code> is not invoked when the signature of the service operation being called is has a return type other then a primitive type, eg:</p>
  
  <pre><code>public IEnumerable&lt;MyType&gt; GetMyType(string s1)
  {
      throw new Exception("Testing...");
  }
  </code></pre>
  
  <p>...will not trigger the <code>ProvideFault</code>.</p>
  
  <p>But:</p>
  
  <pre><code>public bool DoStuff(string s1, string s2)
  {
      throw new Exception("Testing...");
  }
  </code></pre>
  
  <p>...does trigger the <code>ProvideFault</code>.</p>