WCF fault - The creator of this fault did not specify a reason

WCF fault - The creator of this fault did not specify a reason

  • Comments 2

I was throwing a simple WCF FaultException yesterday and came across the same problem as this on the forums

 The client was trying to catch a fault as below:

catch (FaultException<InvalidOperationException> fexc)

{

MessageBox.Show("A fault occurred because of an invalid operation exception"

 

To get it working from a server perspective I had to delcare the following:

InvalidOperationException oe = new InvalidOperationException(

"Debit amount is greater than balance in account " + accountNumber);

FaultException<InvalidOperationException> fe = new FaultException<InvalidOperationException>(oe,

new FaultReason("Debit amount is greater than balance in account " + accountNumber));

throw fe;

I also marked the service interface with the following attribute:

[FaultContract(typeof(InvalidOperationException))]

 

I'm sure there must be a better way.... will followup 

Leave a Comment
  • Please add 2 and 7 and type the answer here:
  • Post
  • Hi,

    What's wrong with the code you have in the post?  

    An

  • The FaultException is a specific type of exception that allows bubbling up fault information into the WCF stack so that it can be mapped it to a SOAP fault. The code I was using did not populate the FaultException with a FaultReason (hence the updated code)

Page 1 of 1 (2 items)