"The creator of this error did not indicate" Exception Cause "

I have the following code in a WCF service to trigger a custom error based on certain situations. I get the exception "The creator of this error did not determine the cause." What am I doing wrong?

//source code if(!DidItPass) { InvalidRoutingCodeFault fault = new InvalidRoutingCodeFault("Invalid Routing Code - No Approval Started"); throw new FaultException<InvalidRoutingCodeFault>(fault); } //operation contract [OperationContract] [FaultContract(typeof(InvalidRoutingCodeFault))] bool MyMethod(); //data contract [DataContract(Namespace="http://myuri.org/Simple")] public class InvalidRoutingCodeFault { private string m_ErrorMessage = string.Empty; public InvalidRoutingCodeFault(string message) { this.m_ErrorMessage = message; } [DataMember] public string ErrorMessage { get { return this.m_ErrorMessage; } set { this.m_ErrorMessage = value; } } } 
+48
c # wcf faults
Dec 04 '08 at 17:49
source share
10 answers

After some additional research, the following modified code worked:

 if(!DidItPass) { InvalidRoutingCodeFault fault = new InvalidRoutingCodeFault("Invalid Routing Code - No Approval Started"); throw new FaultException<InvalidRoutingCodeFault>(fault, new FaultReason("Invalid Routing Code - No Approval Started")); } 
+41
Dec 04 '08 at 19:07
source share

The short answer is: you are not doing anything wrong, just reading the results incorrectly.

On the client side, when you catch an error, what is caught is of type System.ServiceModel.FaultException<InvalidRoutingCodeFault> .
Your InvalidRoutingCodeFault object InvalidRoutingCodeFault actually in the .detail property of the FaultException. SO ....

//Client code

 private static void InvokeMyMethod() { ServiceClient service = new MyService.ServiceClient(); try { service.MyMethod(); } catch (System.ServiceModel.FaultException<InvalidRoutingCodeFault> ex) { // This will output the "Message" property of the System.ServiceModel.FaultException // 'The creator of this fault did not specify a Reason' if not specified when thrown Console.WriteLine("faultException Message: " + ex.Message); // This will output the ErrorMessage property of your InvalidRoutingCodeFault type Console.WriteLine("InvalidRoutingCodeFault Message: " + ex.Detail.ErrorMessage); } } 

The Message property for FaultException is what is displayed on the error page, so if it is not filled, as in the John Egerton column, you will see the message "The creator of this error did not indicate the message" Cause ". To easily fill it, use two parameter constructors when calling an error in the service as follows, passing the error message from your type of error:

 InvalidRoutingCodeFault fault = new InvalidRoutingCodeFault("Invalid Routing Code - No Approval Started"); throw new FaultException<InvalidRoutingCodeFault>(fault, new FaultReason(fault.ErrorMessage)); 
+16
Sep 10 '12 at 20:12
source share
 serviceDebug includeExceptionDetailInFaults="true" 

NOT a solution

The following code even works with serviceDebug includeExceptionDetailInFaults="false"

 // data contract [DataContract] public class FormatFault { private string additionalDetails; [DataMember] public string AdditionalDetails { get { return additionalDetails; } set { additionalDetails = value; } } } // interface method declaration [OperationContract] [FaultContract(typeof(FormatFault))] void DoWork2(); // service method implementation public void DoWork2() { try { int i = int.Parse("Abcd"); } catch (FormatException ex) { FormatFault fault = new FormatFault(); fault.AdditionalDetails = ex.Message; throw new FaultException<FormatFault>(fault); } } // client calling code private static void InvokeWCF2() { ServiceClient service = new ServiceClient(); try { service.DoWork2(); } catch (FaultException<FormatFault> e) { // This is a strongly typed try catch instead of the weakly typed where we need to do -- if (e.Code.Name == "Format_Error") Console.WriteLine("Handling format exception: " + e.Detail.AdditionalDetails); } } 

There is no need to add the cause of the error if it is not required. Just make sure the FaultContract attribute is correct.

+8
Jan 28 '09 at 11:33
source share

I solved this problem using two parameter constructors.

 // service method implementation throw new FaultException<FormatFault>(fault,new FaultReason(fault.CustomFaultMassage)); 

CustomFaultMassage is a property from a data contract.

+3
Jul 08 '10 at 9:17
source share

You may also encounter this exception if you do not specify the FaultContract attribute (typeof (className)) for the method

+2
Jan 28 '09 at 11:21
source share

I have a code exactly the same as Rashmi, and I got the error "Creator of this error ....". This happened when I was debugging in VS2010. I found this post:

http://sergecalderara.wordpress.com/2008/11/25/systemservicemodelfaultexception1-was-unhandled-by-user-code/

which explained a couple of debugging options that I needed to disable. The problem is resolved.

+1
Nov 18 '09 at 0:56
source share

If you do not want to receive notifications about these exceptions, go to "Debug" → "Exceptions" and uncheck the box "Custom raw" for "Exceptions for the duration of the regular language" or for certain exceptions.

+1
Apr 14 '10 at 9:39
source share

You can try this in server settings (behavior → serviceBehaviors →):

 <serviceDebug includeExceptionDetailInFaults="true" /> 
0
Dec 04 '08 at 18:12
source share

Using a strongly typed try catch, I was able to get rid of the error "The creator of this error did not determine the cause."

0
Apr 15 '09 at 0:43
source share

Updating the help desk in the client solved the problem. The same may work for you.

0
Sep 21 '10 at 10:50
source share



All Articles