Even though NavigationService.CanGoBack
returns True
, NavigationService.GoBack()
throws me these exceptions :
A first chance exception of type 'System.ArgumentException' occurred in System.Windows.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in
This happens systematically on two case, while the third works fine :
- Crashes if I call
NavigationService.GoBack()
inOnNavigatedTo()
- Crashes If I call
NavigationService.GoBack()
as a result ofWebException
thrown in myHTTPWebRequest
when Internet is not available [1] - Works fine if Internet is available and I call
NavigationService.GoBack()
when myHTTPWebRequest
got results, parsed them, and displayed them.
My theory is that I can't call GoBack()
too soon after navigating from a page to another... My question : How can I programatically go back up the navigation stack when an HTTPWebRequest
fails to load ?
Edit : I've decided to do it another way, but I think my problems might be due to navigation animations and the Windows Phone C# Toolkit (I use Feb 2011 edition)
[1] Details of my code on case 2 :
I have a simple HTTPWebRequest
. My callback does this, and my app crashes when in Airplane Mode. The line NavigationService.GoBack()
is responsible, even though NavigationService.CanGoBack
returns true
.
try
{
response = request.EndGetResponse(result);
}
catch (WebException)
{
Dispatcher.BeginInvoke(() =>
{
NavigationService.GoBack();
});
}
I tried using Deployment.Current.Dispatcher.BeginInvoke()
also.