title: Including exception details when using a Castle WCF Facility hosted service
body: <p>I'm having some trouble unit testing a bit of code while utilising the Wcf Facility for Castle Windsor. It seems to refuse to include Exception Details when an Exception is thrown, I only get to see empty FaultExceptions. This is my test setup:</p>
  
  <p>First, here's a stub of the service that I will be connecting to:</p>
  
  <pre><code>[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
  public abstract class StubAilDataService : IAilDataService
  {
      public virtual Method1()
      {
      }
      /* More methods */
  }</code></pre>
  
  <p>Notice that I've specified <code>IncludeExceptionDetailsInFaults</code> and set it to <code>true</code>.</p>
  
  <p>This is how I host the stubbed service:</p>
  
  <pre><code>private ServiceHost _host;
  private StubAilDataService _rhinoService;
  
  [TestFixtureSetUp]
  public void FixtureSetup()
  {
      var sba = new ServiceDebugBehavior {IncludeExceptionDetailInFaults = true};
      _rhinoService = MockRepository.GeneratePartialMock&lt;StubAilDataService&gt;();
  
      _host = new ServiceHost(_rhinoService);
      _host.AddServiceEndpoint(typeof(IAilDataService), new WSHttpBinding("wsSecure"), "http://localhost:8080/Service");
      _host.Open();
  
      _container.AddFacility&lt;WcfFacility&gt;().Register(
          Component.For&lt;IServiceBehavior&gt;().Instance(sba),
          Component.For&lt;IAilDataService&gt;()
              .LifeStyle.PerWcfSession()
              .ActAs(new DefaultClientModel
                         {
                             Endpoint =
                                 WcfEndpoint.BoundTo(new WSHttpBinding("wsSecure"))
                                 .At("http://localhost:8080/Service")
                         }) // More stuff
          );
  }
  </code></pre>
  
  <p>I've done a PartialMock in an attempt to keep the Include.. attribute on the mocked object.</p>
  
  <p>And the test. Notice that I tell my mocked service to throw a very specific exception here.</p>
  
  <pre><code>[Test]
  [ExpectedException(typeof(AggregateException))]
  public void AnalyzeProductCreationJobs_Should_Throw_Aggregate_Exception_If_A_DataService_Call_Throws()
  {
      //Arrange
      _rhinoService.Expect(
      s =&gt; s.CategoryIsInAgility(Arg&lt;string&gt;.Matches(str =&gt; str.Equals("000103")), Arg&lt;Settings&gt;.Is.Anything))
      .Throw(new FaultException&lt;InvalidOperationException&gt;(new InvalidOperationException("FAIL!")));
  
      var product = new Product { CategoryCode = "000103" };
  
      var analyzer = TypeResolver.Resolve&lt;ProductAnalyzer&gt;();
  
      //Act
      analyzer.AnalyzeProductCreationJobs(product);
  }
  </code></pre>
  
  <p>And finally, the code I'm actually testing:</p>
  
  <pre><code>public class ProductAnalyzer
  {
      private readonly IDataServiceClient _dataClient;
  
      public ProductAnalyzer(IDataServiceClient dataClient)
      {
          _dataClient = dataClient;
      }
  
      public IEnumerable&lt;IAdsmlJob&lt;CreateResponse&gt;&gt; AnalyzeProductCreationJobs(Product product)
      {
          IList&lt;IAdsmlJob&lt;CreateResponse&gt;&gt; creationJobs = new List&lt;IAdsmlJob&lt;CreateResponse&gt;&gt;();
  
          var task = Task.Factory.StartNew(() =&gt;
          {
              // This is where the exception set up in my .Expect gets thrown.
              bool categoryIsInAgility = _dataClient.CategoryIsInAgility(product.CategoryCode);
              // Logic
          }); // Continued by more tasks
  
      try
      { task.Wait(); }
      catch (AggregateException ae)
      {
          ae.Flatten().Handle(ex =&gt; ex is TaskCanceledException);
      }
  }
  </code></pre>
  
  <p>I would expect the service to crash and throw the exception I've set it up to throw - but the Wcf Facility seems to strip away the exception that is thrown and replace it with an empty FaultException instead.</p>
  
  <p>Am i missing something? There are quite a few components working together here - and I'm not 100% sure where things go wrong.</p>