Introducing RadDiagnostics for Windows Phone

by Valentin Stoychev | Comments 9

As part of the Telerik “Q1.2012 Beta” package for Windows Phone we are releasing a new set of "Application Building Blocks" components. You can find more info on the idea of Application Building Blocks here. Among these components is RadDiagnostics.

Overview

RadDiagnostcs component will enable you to receive crash reports, get specific debug and run-time information from your end users when an issue (ApplicationUnhandledException) in your application is encountered. When an exception occurs, a MessageBox dialog is displayed and users are asked to report the diagnostics data. The collected data contains rich information about the exception, device and runtime info. Optionally a screenshot of the current application state can be provided. Developers can also add custom data when an exception has occurred and to collect runtime logs.

We are already using this component in Telerik “Tasks” application for WindowsPhone and it has proved to be a very valuable helper in debugging and resolving application issues. I strongly recommend you to add such an error reporting component to all of your applications.

Here is how the default user experience for the end users looks like:
Error handling in WindowsPhone/WinRt mobile applications
When users click on the “Yes” button they will be able to send an email message pre-filled with all the data collected from RadDiagnostics.
This is the default user experience. Developers can customize the displayed message and also have an option to skip the message, to get the data and to send it automatically to their own web service for analyzing (this requires additional development and is not provided out of the box).

The usage of the control is quite simple and intuitive:

RadDiagnostics diagnostics = new RadDiagnostics();
diagnostics.EmailTo = “myemail@mail.com”;
diagnostics.Init();

This initialization code should be added in the App constructor.

To create a custom action and to get notified when an exception has occurred, you can subscribe to the ExceptionOccured event:

radDiagnostics.ExceptionOccurred += new EventHandler<ExceptionOccurredEventArgs>(RadDiagnostics_ExceptionOccurred);
private void RadDiagnostics_ExceptionOccurred(object sender, ExceptionOccurredEventArgs e)
 {
  //e.Cancel = true; setting Cancel to true will prevent the message box from displaying.
  
   // add any custom code here, like reporting to a custom web service
  //SendDiagnosticsToWebService((sender as RadDiagnostics).DiagnosticInfo);
 }

Diagnostic Data

You are maybe now curious to see what data you will receive when an error is encountered. Here is a sample error report:

[StackTrace]:[ 
Navigation is not allowed when the task is not in the foreground. Error: -2147220990
   at Microsoft.Phone.Scheduler.SystemNotificationInterop.CheckHr(Int32 hr)
   at Microsoft.Phone.Scheduler.SystemNotificationInterop.CreateNotification(ScheduledAction action)
   at Microsoft.Phone.Scheduler.ScheduledActionService.Add(ScheduledAction action)
   at Telerik.WindowsPhone.Tasks.ApplicationHelpers.ScheduleMasterTileUpdateAgent()
   at Telerik.WindowsPhone.Tasks.App.Application_Launching(Object sender, LaunchingEventArgs e)
   at Microsoft.Phone.Shell.PhoneApplicationService.FireLaunching()
   at Microsoft.Phone.Execution.NativeEmInterop.FireOnLaunching()
]
[OccurrenceDate]:[Tue, 31 Jan 2012 12:41:48 GMT]
[AppInstallDate]:[Sun, 29 Jan 2012 19:00:42 GMT]
[AppTotalRuns]:[4]
[AppRunsAfterLastUpdate]:[4]
[AppPreviousRunDate]:[1/29/2012 2:01:54 PM]
[AppVersion]:[1.33]
[Culture]:[en-US]
[CurrentPageSource]:[/Views/SyncProvidersList.xaml?SyncProviderId=1]
[NavigationStack]:[/Views/MainPage.xaml]
[DeviceManufacturer]:[HTC]
[DeviceModel]:[mwp6985]
[DeviceHardwareVersion]:[0003]
[DeviceFirmwareVersion]:[2305.13.20104.605]
[OSVersion]:[Microsoft Windows CE 7.10.7720]
[CLRVersion]:[3.7.11140.0]
[DeviceType]:[Device]
[NetworkType]:[Wireless80211]
[DeviceTotalMemory(Mb)]:[475.375]
[AppPeakMemoryUsage(Mb)]:[4.828125]
[AppCurrentMemoryUsage(Mb)]:[4.828125]
[IsoStorageAvailableSpace(Mb)]:[2909]

As you can see we are collecting a lot of data which will be useful for you when debugging the problem. If this is not sufficient enough RadDiagnostics can be used as a simple logger to collect any runtime info you are providing. Here is a simple usage of the logging feature:

radDiagnostics.AddDebugInfo(String.Format("filterData = {0}", filterDate));

In order to keep the performance of your application high logs will contain only the last 1Mb of data. Please keep this in mind when using this feature.

Another cool feature (and my favorite one I must admit :)) of RadDiagnostics is how the mail Subject is composed. Apart from the obvious info – ApplicationName and ApplicationVersion – it contains the Hashcode of the Stack Trace!!! This allows you to group the mails you receive and see which error is occurring most often – thus seeing the top priority issues.

Here is how my inbox looks like for the Tasks application crash reports:

I hope that this component will be very useful for you as it is for us in Tasks application. Please give it a try during the beta period and let us know if you have suggestions for enhancements.

You can also find me on twitter @valiostoychev  – I’ll be happy to discuss any feedback you have!

,
Team Leader,
Windows Phone Team

 

9 Comments

Erik Umenhofer
This looks awesome. My main problem with WP7 is that the most common error is the one that is almost untraceable.
Gary Davis
I was unable to get this to work. I was not sure if I needed the second box of code above to subscribe to the exception for the default (simple) case, I did not think so but I tried both ways and the exception is not caught and no popup is displayed.
BTW, the second box has a typo. radDiagnostics.ExceptionOccurred should be
diagnostics.ExceptionOccurred to match the 1st box code.
I put the 1st box three stmts into the App() constructor (at the end after the call to InitializePhoneApplication().
Do I need anything else? Perhaps something in Application_UnhandledException?
Thanks,
Gary Davis
Webguild.com
chefdog
Very nice! This was what I wanted to build, now I am going to use this control!!
Bjorn
Where can i find the

ApplicationRuntimeHelper.Init()
function/class?

Bjorn
oh wait, beta...
Wim
I tried it too, but I get an Invalid Cross Thread exception.
As far as i can see, the origin of the exception is in the RadDiagnostics tool.
Wim
This is actually the stacktrace :
   at MS.Internal.XcpImports.CheckThread()
   at System.Windows.Application.remove_UnhandledException(EventHandler`1 value)
   at Telerik.Windows.Controls.RadDiagnostics.f(Object A_0, ApplicationUnhandledExceptionEventArgs A_1)
   at MS.Internal.Error.CallApplicationUEHandler(Exception e)
   at MS.Internal.JoltHelper.OnUnhandledException(Object sender, UnhandledExceptionEventArgs args)
And this is the exception : Invalid cross-thread access.
Valentin
Wim, we are not aware of such a problem. Please use our forums or send us a support ticket with more details about the way you are using the component.



Thank you!
Read more articles by Valentin Stoychev - or - read latest articles in Developer Tools