0

I'm developing a Windows Phone App. I submitted it to Microsoft and they sent me back a file describing an error that occurs when resuming the app (it's relative to the 5.2 Performance and Resource Management, point 5.2.3).

To reproduce the error, I run the app, I start on the start button to go to the "desktop" and click on the "Back" button. After that, the visual studio highlights in yellow the System.Diagnostics.Debugger.Break(); line in this code

// Code to execute on Unhandled Exceptions
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        { 
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // An unhandled exception has occurred; break into the debugger
                System.Diagnostics.Debugger.Break();
            }
        } 

With the stacktrace, I found that the last called method was CallApplicationUEHandler.

So, is it a known exception? Did I forget to handle some exceptions?

Here are the last three lines of output just above the the call of CallApplicationUEHandler:

first chance exception 'System.ArgumentNullException' in Microsoft.Phone.Controls.dll
first chance exception 'System.ArgumentException' in System.Windows.dll
first chance exception 'System.ArgumentException' in System.Windows.dll

The constructors:

For the MainPage:

public MainPage()
        {
            journal.Debug(string.Format("Entrée méthode {0}", new StackTrace().GetFrame(1).GetMethod().Name));
            InitializeComponent();

            Loaded += new RoutedEventHandler(PhoneApplicationPage_Loaded);
        }



private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        mainVM = new MainViewModel();
        DataContext = mainVM;
    }

For the App:

public App()
        {
            // Global handler for uncaught exceptions. 
            // Note that exceptions thrown by ApplicationBarItem.Click will not get caught here.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone- {2} -specific initialization
            InitializePhoneApplication();
        }

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
           if (System.Diagnostics.Debugger.IsAttached)
            {
                // An unhandled exception has occurred; break into the debugger
                System.Diagnostics.Debugger.Break();
            }
        } 
Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
Zakaria
  • 14,892
  • 22
  • 84
  • 125
  • `CallApplicationUEHandler` was the top thing because that's what set off the chain of events to your unhandled exception handler. What is the *rest* of the stack trace? the thing right below that on the stack would give us more information to help you. Is there an `InnerException` with more details? – John Gardner Jan 13 '11 at 17:58
  • @John Gardner: I have nothing below. But the last three debug lines contain first chance exceptions. I edited the post to show them. – Zakaria Jan 14 '11 at 16:07
  • Can you confirm that the app has finished fully loading before you first navigate away? – Matt Lacey Jan 14 '11 at 16:35
  • I have the eccept same error massages. Driving me nuts. In my case the app will sometimes not start. –  Jan 21 '11 at 00:38

2 Answers2

1

By the fact Application_UnhandledException is being called it's fairly likely you're not handling an exception somewhere.

Debug this by looking at the page constructor of the page being loaded and also the OnNavigatedTo event handler, if you have one.

At the app level, look at what you're doing in Application_Activated.

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
0

Put your code in Try-Catch Block. I was also facing such problem, but then handled by Exception Handling Method.

try
 {

   // your code

 }

catch (Exception ex)
 {

   throw (ex);
 }
Zia Ur Rahman
  • 1,850
  • 1
  • 21
  • 30