0

I am throwing an exception in a Silverlight enabled service and catching it in my silverlight client. I have done everything as per the manual, but still getting what I think is unexpected behavior.

Code from Client

 try { client.ThrowFaultExceptionCompleted += (s, args) => { DoCallback(args); }; client.ThrowFaultExceptionAsync(new ThrowFaultExceptionRequest()); } catch (FaultException<MyFaultException> myFex) { } catch (FaultException fex) { } 

Here is the code from the service

My Custom Fault Exception class

[DataContract] public class MyFaultException { private string _reason; private string _myExceptionStackTrace; [DataMember] public string Reason { get { return _reason; } set { _reason = value; } } [DataMember] public string MyExceptionStackTrace { get { return _myExceptionStackTrace; } set { _myExceptionStackTrace = value; } } } 

The bit of service side code that throws the fault exception. For testing purposes I am calling this method from the client.

 [OperationContract] [FaultContract(typeof(MyFaultException))] public void ThrowFaultException() { MyFaultException mfex = new MyFaultException(); mfex.Reason = "No Reason!"; mfex.MyExceptionStackTrace = "Long stack trace here"; System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK; //throw new FaultException<MyFaultException>(mfex ,new FaultReason(new FaultReasonText("My Fault Reason Text here!")), new FaultCode("my fault code here")); throw new FaultException<MyFaultException>(mfex); } 

no matter if I throw the FaultException with a single param or those three params in the commented line I get an error in my Reference.cs file in the silverlight proxy class like the one below

error message in reference.cs

and it doesnt ever go to either of the catch blocks.. Is this normal behavior? I have to now catch the error in the callback method DoCallback(args) and in that method check for (args.Error == null). Why doesnt the catch block get hit?

Thanks for your time...

6
  • Why have you commented the line with the FaultReason parameter? The error message requires to specify that reason. Commented Jun 11, 2011 at 8:57
  • I thought it would stop the error in the image above. The reason is packaged in the MyFaultException object. Commented Jun 11, 2011 at 10:30
  • @user20358 If you uncomment the line throw new FaultException<MyFaultException>(mfex ,new FaultReason(... the exception message will be different. Try to do this and update your question with information about changes. Commented Jun 11, 2011 at 12:40
  • the problem is I get this error in my reference.cs file also. I want to get this error in the silverlight client only. If I uncomment the line I get "My Fault Reason Text here!" in place of "The creator of this fault didn't specify a reason". Since this is a study project I dont care about the message at this point. I am only concerened at it coming in my reference file. I dont want the service to bomb when I have deployed it. Commented Jun 11, 2011 at 13:42
  • @user20358 Ok, I've tested your code. In my case this message appears on the service side and in the file Reference.cs. But the exception is handled by the autogenerated code and can be accessed from the callback event args. So it is normal behavior, use only the check operation, you can remove the try-catch block from the client code. Commented Jun 12, 2011 at 16:40

1 Answer 1

3

Found something that might be useful. You need to change the debugging settings in Visual studio.

Go to Tools -> Options -> Debugging -> General and uncheck "Enable the exception assistant" and "Enable Just My Code (Managed only)"

Sign up to request clarification or add additional context in comments.

1 Comment

Its been over a year that I have worked on SL projects, but I will check out your recommendation and report back soon as I get the time. Many thanks. Appreciate you sharing this. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.