This project is read-only.

how to troubleshoot or display errors

Jul 6, 2009 at 5:52 PM

Seems like a lot of people get just a blank slideshow if there's any sort of error. Any way to enable errors or disable error traps so that errors bubble up and we can get an error message? Not a problem when debugging since you drop into code...but is a problem when things work fine in development but then blow up on the server.

Jul 7, 2009 at 2:35 PM
Edited Jul 7, 2009 at 2:36 PM

Hi,

you can show errors from SL following this steps:

1. add a script to your page:

    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            }
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;
           
            var errMsg = "Unhandled Error in Silverlight 2 Application " +  appSource + "\n+ "<br>"" ;

            errMsg += "Code: "+ iErrorCode + "    \n"+ "<br>";
            errMsg += "Category: " + errorType + "       \n"+ "<br>";
            errMsg += "Message: " + args.ErrorMessage + "     \n"+ "<br>";

            if (errorType == "ParserError")
            {
                errMsg += "File: " + args.xamlFile + "     \n"+ "<br>";
                errMsg += "Line: " + args.lineNumber + "     \n"+ "<br>";
                errMsg += "Position: " + args.charPosition + "     \n"+ "<br>";
            }
            else if (errorType == "RuntimeError")
            {          
                if (args.lineNumber != 0)
                {
                    errMsg += "Line: " + args.lineNumber + "     \n"+ "<br>";
                    errMsg += "Position: " +  args.charPosition + "     \n"+ "<br>";
                }
                errMsg += "MethodName: " + args.methodName + "     \n"+ "<br>";
            }
            document.getElementById('errorLocation').innerHTML = errMsg;
        }
    </script>

2. add a div to the html page to display the error:

<div id='errorLocation' style="font-size: small;color: Gray;"></div>

3. add a "onerror"-param to your sl object tag:

<object data="data:application/x-silverlight," type="application/x-silverlight-2">
 <param name="source" value="Vertigo.SlideShow.xapx" />
 <param name="onerror" value="onSilverlightError" />
 <!-- other stuff... -->
 </object>

4. find the source code you want to produce a "visible" error, i.e. in XmlDataProvider and XmlConfigurationProvider client_DownloadStringCompleted:

public void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
     if (e.Error != null) throw e.Error.InnerException; //this will be shown in the div tag in the html page
     //other code...

 Olaf