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.
I know this comes over two years beyond the original post, but maybe this will help someone looking for an answer to this question. I kept getting apparently random System.ExecutionEngineExceptions from a Window 10 UWP desktop app. After several days, I found the answer for my particular problem. I had used a MVVM platform, and the x:UID in one of my views had become corrupted.
IT SHOULD HAVE BEEN: <TextBlock x:Uid="Battery ...
IT WAS: <TextBlock x:Uid="=Battery"
The error was not flagged as a XAML problem, as many syntax errors similar to this are but once I corrected that error, by removing the unneeded equal sign, the exception went away.
Hope this helps someone else.
Clyde
Also want to add to the above. The XAML engine does not check for duplicate x:Uid and I also got this error when I had two x:Uid's with the same name. Made all x:Uid's throughout my project unique (unfortunately expands the resource file) but that resolved any further issues. Wished that the XAML designer checked for duplicate x:Uid's the was it does for x:Name's.
Again, hope it helps someone in the future.
Cheers,
Clyde
For those encountering ExecutionEngineException while using Xamarin, make sure you have the latest version of Microsoft.NETCore.UniversalWindowsPlatform.
The issue was fixed in UWP 6.2.12:
Fix to execution engine exception when loading InAppUI in Xamarin.
https://github.com/microsoft/dotnet/blob/main/releases/UWP/net-native2.2/README.md
Related
The issue:
We have an application written in C# that uses UIAutomation to get the current text (either selected or the word behind the carret) in other applications (Word, OpenOffice, Notepad, etc.).
All is working great on Windows 10, even up to 21H2, last update check done today.
But we had several clients informing us that the application is closing abruptly on Windows 11.
After some debugging I've seen some System.AccessViolationException thrown when trying to use the TextPatternRange.GetText() method:
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
What we've tried so far:
Setting uiaccess=true in manifest and signing the app : as mentionned here https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/350ceab8-436b-4ef1-8512-3fee4b470c0a/problem-with-manifest-and-uiaccess-set-to-true?forum=windowsgeneraldevelopmentissues => no changes (app is in C:\Program Files\
In addition to the above, I did try to set the level to "requireAdministrator" in the manifest, no changes either
As I've seen that it may come from a bug in Windows 11 (https://forum.emclient.com/t/emclient-9-0-1317-0-up-to-9-0-1361-0-password-correction-crashes-the-app/79904), I tried to install the 22H2 Preview release, still no changes.
Reproductible example
In order to be able to isolate the issue (and check it was not something else in our app that was causing the exception) I quickly made the following test (based on : How to get selected text of currently focused window? validated answer)
private void btnRefresh_Click(object sender, RoutedEventArgs e)
{
var p = Process.GetProcessesByName("notepad").FirstOrDefault();
var root = AutomationElement.FromHandle(p.MainWindowHandle);
var documentControl = new
PropertyCondition(AutomationElement.ControlTypeProperty,
ControlType.Document);
var textPatternAvailable = new PropertyCondition(AutomationElement.IsTextPatternAvailableProperty, true);
var findControl = new AndCondition(documentControl, textPatternAvailable);
var targetDocument = root.FindFirst(TreeScope.Descendants, findControl);
var textPattern = targetDocument.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
string text = "";
foreach (var selection in textPattern.GetSelection())
{
text += selection.GetText(255);
Console.WriteLine($"Selection: \"{selection.GetText(255)}\"");
}
lblFocusedProcess.Content = p.ProcessName;
lblSelectedText.Content = text;
}
When pressing a button, this method is called and the results displayed in labels.
The method uses UIAutomation to get the notepad process and extract the selected text.
This works well in Windows 10 with latest update, crashes immediately on Windows 11 with the AccessViolationException.
On Windows 10 it works even without the uiaccess=true setting in the manifest.
Questions/Next steps
Do anyone know/has a clue about what can cause this?
Is Windows 11 way more regarding towards UIAutomation?
On my side I'll probably open an issue by Microsoft.
And one track we might follow is getting an EV and sign the app itself and the installer as it'll also enhance the installation process, removing the big red warnings. But as this is an app distributed for free we had not done it as it was working without it.
I'll also continue testing with the reproductible code and update this question should anything new appear.
I posted the same question on MSDN forums and got this answer:
https://learn.microsoft.com/en-us/answers/questions/915789/uiautomation-throws-accessviolationexception-on-wi.html
Using IUIautomation instead of System.Windows.Automation works on Windows 11.
So I'm marking this as solved but if anyone has another idea or knows what happens you're welcome to comment!
I'm trying to throw together a simple app that uses pedometer data on a Windows 10 phone. I normally live down in kernel-land, and this is my first time using most of the c# async stuff, so I'm wondering if I'm missing a core concept here.
My first attempt at getting data out was to simply report the number of recorded steps over the last hour to a textbox in my XAML app. I just created a basic XAML app, dropped a text box in, and added this event handler:
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
var history = await Pedometer.GetSystemHistoryAsync(DateTimeOffset.Now.AddHours(-1), TimeSpan.FromHours(1));
int count = history.Sum(entry => entry.CumulativeSteps);
textSteps.Text = count.ToString();
}
A breakpoint on the first line triggers, but before it hits the next line I get an unhandled exception. Error code -2147467259, message "Error HRESULT E_FAIL has been returned from a call to a COM component."
The top frame of the stack is in my code, but it's just the boilerplate line from App.g.i.cs that triggers a break on an unhandled exception. Below that is mscorlib and the WinRT invoker.
I looked through the app capabilities list in the manifest, and didn't find anything that looked like it applied to the pedometer. I'm testing this on a Lumia 950.
UPDATE: I just tried calling the API to get the default pedometer sensor:
Pedometer p = await Pedometer.GetDefaultAsync();
It turns out that this triggers an access denied exception with the same worthless stack. I'm currently doing more research to see if there is something that needs to be specified in the manifest.
After further experimenting got me an access denied error, I looked into the manifest more. The manifest Microsoft example project for the pedometer declares a device property that I can't find a way to add through the designer view. Adding it to the code worked perfectly. It's saying I've taken 300,000 steps in the last hour, but I'm sure some simple debugging will find the answer there. (The property is called CumulativeSteps, so that's a good hint...)
<Capabilities>
<DeviceCapability Name="activity" />
</Capabilities>
var currentReadings = await Pedometer.GetSystemHistoryAsync(DateTime.Today);
var walklist = new List<PedometerReading>();
var runlist = new List<PedometerReading>();
foreach (var cuurentreading in currentReadings)
{
if (cuurentreading.StepKind == PedometerStepKind.Walking)
{
walklist.Add(cuurentreading);
}
if (cuurentreading.StepKind == PedometerStepKind.Running)
{
runlist.Add(cuurentreading);
}
}
var item = walklist.Last();
var item1 = walklist.First();
var item2 = runlist.Last();
var item3 = runlist.First();
Steps1.Value += (item.CumulativeSteps - item1.CumulativeSteps);
Steps1.Value += (item2.CumulativeSteps - item3.CumulativeSteps);
Me and some of my colleagues are working on a project together, and have encountered a weird issue we can't manage to fix.The project involves the creation of a VNC connection between a client and a server, and is written in C# (we're using Visual Studio 2010). We're using the VNCSharp library for the client.The issue I speak of is that once we start the connection with the server, an ArgumentException is thrown.
Some of the information supplied was this:
********** Exception Text **********
System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at VncSharp.RemoteDesktop.SetupDesktop()
at VncSharp.RemoteDesktop.Initialize()
at VncSharp.RemoteDesktop.Connect(String host, Int32 display, Boolean viewOnly, Boolean scaled)
at VncSharp.RemoteDesktop.Connect(String host)
at RemoteDesktopTest.Form2.startConnection()
Another weird thing about this is that it only occures some of the times, whereas in others it works perfectly well. Specifically, it always works when run in debug mode (i.e, when we run the program line-by-line using F11), and either works or doesn't work when run regularly (i.e Ctrl+F5), without any pattern we could recognize.
We would be really grateful for any and all help; if there are any details I can add that would assist in the answering of this question, please let me know.
Additionally, I apologize for any grammar/spelling mistakes; English is not my first language... and I also apologize if something about this question is not alright. We're all beginners and this is our first "big project", so this is also my first time asking a question in Stack Overflow.
EDIT:
There are some parts of the code that are potentially relevant.
These are the lines of code automatically generated after we added the VncSharp control to the form and customized its settings:
this.remoteDesktop1 = new VncSharp.RemoteDesktop();
this.remoteDesktop1.AutoScroll = true;
this.remoteDesktop1.AutoScrollMinSize = new System.Drawing.Size(608, 427);
this.remoteDesktop1.Dock = System.Windows.Forms.DockStyle.Fill;
this.remoteDesktop1.Location = new System.Drawing.Point(0, 0);
this.remoteDesktop1.Name = "remoteDesktop1";
this.remoteDesktop1.Size = new System.Drawing.Size(1113, 580);
this.remoteDesktop1.TabIndex = 1;
This is the line of code in which I call the Connect method, while IP is simply the string taken from a text box:
remoteDesktop1.Connect(this.IP);
These are from the method which handles the ConnectComplete event (e is the EventArgs object passed to the method):
this.Location = new Point(0,0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
this.remoteDesktop1.Size = new System.Drawing.Size(e.DesktopWidth, e.DesktopHeight);
Aside from the line in which the Disconnect method is called, we've written literally no other lines of code that deal with this object. If I'll realize I'd forgotten something, I'll edit again and add it. Also, if there's anything specific in the code I should add here, please let me know.
The issue was related to timing, it seems.
Out of debug mode, the program ran too fast and those width and height variable didn't have their values updated.
Luckily, VncSharp is open source, so I could add my own line and leave it in a loop as long as either of those two variables still has its default value, and now it works.
Thanks for the help, everyone :)
Had the same problem. For me it worked to compile the vncsharp solution in debug mode.
In RfbProtocol line 398 (first line of the ReadServerInit method), I transformed
int w = Reader.ReadUInt16();
to
int w = 0;
while (w == 0)
w = Reader.ReadUInt16();
I have created an application where i have placed out the adcontrols. I have also configured the IDs for my application though yet no ads are displaying after the change. I have both tested it through the emulator and on my own Windows Phone yet the ads are not showing, what could be the problem?
I had the same problem.. What worked for me is setting the height and width of the AdControl in the code too (not just in xaml).
This might not work for.. so to clearly understand where you are going wrong add adcontrol.erroroccured function. My code goes something like this.
public HomePage()
{
InitializeComponent();
String AppId = SResources.Ad_App_ID;
String AdUnitID = SResources.Ad_Unit_ID;
sAdControl.AdUnitId = AdUnitID;
sAdControl.ApplicationId = AppId;
sAdControl.Width = 480;
sAdControl.Height = 80;
sAdControl.ErrorOccurred += new EventHandler<Microsoft.Advertising.AdErrorEventArgs>(sAdControl_ErrorOccurred);
}
void sAdControl_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)
{
string error=e.Error.ToString();
}
Hope this helps!! :)
The problem still persists! Though i know why now and it was nothing with wrong codes or anything.
Microsoft are having problems with their adserver and several people are having the same issues as me.
Seems like this has all begun now in january 2013. People cant even see the test Adcontrols anymore and neither can i. This is a problem with Microsoft that they have to resolve.
Im posting this link to their forums so you can read more and understand that several others have similiar problems with the Adcontrols. Hope this helps!
http://community.bingads.microsoft.com/ads/en/publisher/f/32/t/74426.aspx
Regards William!
I had the same problem. I implemeted
void sAdControl_ErrorOccurred
to discover that capability were missing, so I added ID_CAP_PHONEDIALER, ID_CAP_IDENTITY_USER, ID_CAP_MEDIALIB, ID_CAP_WEBBROWSERCOMPONENT , an now it works good.
In my project, I need to add two UIBarButtonItems to a NavigationItem of a view controller. I solved this with this code:
UIBarButtonItem saveButton = new UIBarButtonItem("Save", UIBarButtonItemStyle.Bordered, (sender, e) => {
//some saving code...
});
UIBarButtonItem delButton = new UIBarButtonItem("Delete", UIBarButtonItemStyle.Done, (sender, e) => {
//some deletion code...
});
UIBarButtonItem[] items = new UIBarButtonItem[]
{
saveButton,
delButton
};
this.NavigationItem.RightBarButtonItems = items;
It worked in previous versions of MonoTouch (on iOS 5, both device and simulator), but (I think so) after I upgraded to MonoTouch 6, only first button from the array is displayed.
I try to use NavigationItem.SetRightBarButtonItems(items, false) method, but without any effect.
Is it a common problem or I am doing something wrong?
Is it a common problem or I am doing something wrong?
Touch.Unit, MonoTouch's unit test runner, use RightBarButtonItems and works correctly (showing both buttons) with MonoTouch 6.0.x.
OTOH I see nothing wrong in your code snippet (but it's a short one). Your best bet is to create a small, self contained, application that shows your issue and attach it to a bug report. We'll be able to review it and see what's wrong (or you might find the issue yourself, if it's inside your own code, when doing the test case).
OK, here is the case. The situation described in my question happens when you already have a back button and a some custom view (i.e. UISegmentedControl instance) in a navigationItem.TitleView. In this case, when you set navigationItem.RightBarButtonItems with an array of UIBarButtonItems and the space is not enough to display a navigationItem.TitleView and both right buttons, iOS renders only the first button of the array and discard the other.
I verified this in a native ObjC application and got the same behavior.