I am developing a Windows Phone 8.1 app. It works fine on WP 8 and WP 8.1 devices, but on the device with Windows 10 it throws
ExecutionEngineException was unhandled. An unhandled exception of type 'System.ExecutionEngineException' occurred in Unknown Module.
in various sections in both "Debug" and "Release" without any data about what went wrong. There are some places, where the exception is always thrown and some, where it's thrown from time to time. Example code below throws the exception - it is basically a method to switch between tabs, which are StackPanels when the button (Grid with Image) is tapped:
private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
{
if(!isMapVisible)
{
hideSection();
map_wrapper.Visibility = Windows.UI.Xaml.Visibility.Visible;
map_button.Background = new SolidColorBrush(ColorHelper.FromArgb(0xFF, 40, 110, 73));
map_icon.Source = new BitmapImage(new Uri(FileHelper.getIconPath("tu_2.png")));
isMapVisible = true;
}
}
private void hideSection()
{
if(isMapVisible)
{
map_button.Background = new SolidColorBrush(ColorHelper.FromArgb(0xFF, 238, 238, 238));
map_icon.Source = new BitmapImage(new Uri(FileHelper.getIconPath("tu.png")));
isMapVisible = false;
map_wrapper.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
else if(isPhotoVisible)
{
photo_button.Background = new SolidColorBrush(ColorHelper.FromArgb(0xFF, 238, 238, 238));
photo_icon.Source = new BitmapImage(new Uri(FileHelper.getIconPath("photo_green.png")));
isPhotoVisible = false;
image_wrapper.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
else if(isListVisible)
{
list_button.Background = new SolidColorBrush(ColorHelper.FromArgb(0xFF, 238, 238, 238));
list_icon.Source = new BitmapImage(new Uri(FileHelper.getIconPath("!2.png")));
isListVisible = false;
news_wrapper.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
}
Finally I managed to fix the code. However the error wasn't in the code above. I used something called "Safe Navigation". The example is shown in the code below:
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootFrame.Navigate(typeof(MainPage));
});
I also handled all asynchronous methods with await
operator (I had left some of them before to run asynchronously). One of those improvements fixed the error.