FaultException(TDetail) Constructor (TDetail)

FaultException<TDetail> Constructor (TDetail)

Initializes a new instance of the FaultException<TDetail> class that uses the specified detail object.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public FaultException(
	TDetail detail


Type: TDetail
The object used as the SOAP fault detail.

The detail object must be serializable or an exception is thrown when the FaultException<TDetail> is serialized.

The following code example shows how a service uses the FaultException<TDetail> type to throw a managed exception that gets converted into the SOAP fault specified by the FaultContractAttribute.

using System;
using System.Collections.Generic;
using System.Net.Security;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace Microsoft.WCF.Documentation
  public interface ISampleService{
    string SampleMethod(string msg);

  public class GreetingFault
    private string report;

    public GreetingFault(string message)
      this.report = message;

    public string Message
      get { return this.report; }
      set { this.report = value; }

  class SampleService : ISampleService
  #region ISampleService Members

  public string  SampleMethod(string msg)
    Console.WriteLine("Client said: " + msg);
    // Generate intermittent error behavior.
    Random rnd = new Random(DateTime.Now.Millisecond);
    int test = rnd.Next(5);
    if (test % 2 != 0)
      return "The service greets you: " + msg; 
      throw new FaultException<GreetingFault>(new GreetingFault("A Greeting error occurred. You said: " + msg));


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft