Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Silverlight Exceptions Via the ErrorWindow

, 9 Jun 2010
Rate this:
Please Sign up or sign in to vote.
The Silverlight navigation app ErrorWindow exposes the last exception thrown, but doesn't show the INNER exceptions. Here's how you can do it.
For the last THREE WEEKS, I've been trying to get a WCF service stood up on a remote secure server, and access it from a Silverlight navigation application on another secure remote server. It's throwing an exception, and referring me to the inner exception. The problem is that this exception is only thrown whn I try to hit the service when it's deployed on a remote server (as opposed to running the service on my development machine), and the inner exception was not available to me. After some LONG pndering, I came up with a solution.
 
The exception reporting mechanism in Silverlight navigation apps is through a class called ErrorWindow. This class has a single constructor that accepts an Exception parameter. The problem is that it only shows the top-most exception, and doesn't iterate through all inner exceptions. My solution was to overload the constructor, like so:
 
public ErrorWindow(string message)
{
    InitializeComponent();
    ErrorTextBox.Text = message;
}
 
and then I wrote this method in a static class:
 
//--------------------------------------------------------------------------------
public static string GetTotalException(Exception ex)
{
    StringBuilder result = new StringBuilder(ex.Message);
    result.AppendFormat("{0}{1}", Environment.NewLine, ex.StackTrace);
    if (ex.InnerException != null)
    {
        result.AppendFormat("{0}============{0}Inner exception: {1}", 
                            Environment.NewLine, 
                            GetTotalException(ex.InnerException));
    }
    return result.ToString();
}
 
Finally, I call it something like this:
 
string errorText = GetTotalException(e);
ErrorWindow window = new ErrorWindow(errorText);
 
This allowed me to copy/paste the entire exception chain from the displayed ErrorWindow in my silverlight application.
 
I still haven't found a resolution to connectivity issue, but now I'm better armed to help others to help me.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

John Simmons / outlaw programmer
Software Developer (Senior)
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.
 
My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

Comments and Discussions

 
GeneralThanks for sharing Pinmemberlinuxjr9-Jun-10 6:42 
GeneralThanks PinmemberSimon_Whale9-Jun-10 6:14 
never thought of getting inner exceptions that way
 
Thank you
Marc Clifton wrote:
That has nothing to do with VB. - Oh crap. I just defended VB!


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 9 Jun 2010
Article Copyright 2010 by John Simmons / outlaw programmer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid