Application crash on device when compiled with .NET Native
Application crashes randomly on a physical device when compiled with .NET Native for ARM. Running processes info show rapid memory usage grow up to >180 Mb. When compiled with plain .NET (not .NET Native) there is no such problem.
Additional information: application crashes when there is ListView control on hosted in the Shell sub-page. Application crahses randomly when scrolling ListView or sliding in FlipView. There is no problem with GridView and there is no problem on PC x86 or x64, no problem when solution is not compiled using .NET Native chain. There is no problem in earlier versions, only in a few latest versions of Template 10! ~~It seems that application is crashed due to out of memory error (see rapid memory usage growth).~~ (update: the problem is not caused by out of memory) Problem occured not only in my project, for other people too. Problem forced another developer to rollback version of Template 10 to a earlier one.
Is anyone else seeing this? @Windows-XAML/community
I've had it crash on some pages with ListViews but it wasn't attached to the debugger so I don't know if it's the same issue. It was a release build with .Net Native.
@diogorolo I experimented with crashes and it is clear - it crashes only when it is compiled with .NET Native. Same code deployed on same device but compiled without .NET Native did not crash. Also, I read on some developer forum this crashes is linked to a Template10 some way. Developer reported on a forum (sorry, it's in russian language) issue appeared after a Template10 upgrade and when he is rolled back to a earlier version, issue with a .NET Native crashes and ListView go away. He was very angry and wrote he is tired of a Template10 lack of stability.
@Opiumtm can you try this:
Switch to Release mode, enable .Net Native compilation (if you've turned it off) like this:

Now, turn on Native debugging like this:

Next, set Exception Settings as shown:

Now, run the app in the debugger. You may have to ignore any try/catch exceptions in your own code and in template10's scaffolding but you should eventually get to the point where you have the problematic listview showing. Once that happens, reproduce the crash and paste as much of the stack trace from the native debugger in here as possible. It will at least give us something to look at in terms of what could be causing the problem.
Yes! I reproduced this random crash on ARM device and have a stack trace clearly indicating this is a Template10 issue!
System.UnauthorizedAccessException: Access is denied. (Excep_FromHResult 0x80070005)
at SharedLibrary!
I think there is critical error in Template10. This error absolutely prevents production deployment of applications on real ARM devices, and must be fixed immediately. And worst of all, this issue reproduce only on an actual ARM devices when application compiled with .NET Native. It can not be reproduced on a x86 PC, on windows 10 mobile emulator or in debug builds on any device family. But real handheld usage is ARM compiled with .NET Native (Microsoft does not accept in store appications compiled for classic .NET, only compiled for .NET Native). For now I can not publish beta version of my application because of this Template10 Issue.
Yes this is a very serious bug. I have some of this error in my app, i hope it was fixed very soon and also nuget package is updated!
I also got this from the Application Insights:
at SharedLibrary!
The first occurrence was 4th Fev.
Thanks for everybody's feedback.
Note that T10 is open source for a reason: It's done by volunteers. It's easy to file issues and complain, but it's much more productive to fork the code and fix the problem about which you're complaining.
So... Those not willing to do this will yes, be waiting on a volunteer to find and fix the root cause. We'll do our best and these stack traces and date info will go a good way to assisting us. If anybody can help to pinpont even further, that will speed up the process even more.
Thanks!
My initial hypothesis just looking at the code is we're encountering the UnauthorizedAccessException due to UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Touch; in CalculateBackVisibility as this method is triggered by Dependency Properties. The call for GetForCurrentView() should likely be marshalled to the Dispatcher via RunAsync().
I've not tested this hypothesis, though.
I'm wondering if the reason we've not seen it until now is because this commit (for #495) fixed a problem where the PropertyChangedCallback wasn't being registered as it should've been. This change was made 14 days ago. I settle on this commit due to the fact that the vast majority of the file has been in place since last fall.
The only other recent-ish commits are for #478, 29 days ago.
I'm going to leave the fix for this issue to @JerryNixon since he was the one who committed the changes I've cited here as he likely understands better what he was going for and what should be happening.
@bc3tech @JerryNixon developer on a forum reported last version without this issue was 1.1.1 Upgrade to a 1.1.2 and later results in a random crashes on a mobile device. Hope, this information about exact broken build is helpful.
@JerryNixon can you go back and drop tags when we did nuget releases? I'm going to have a look at when this might've been now and will report back.
For a few weeks ago I had a similar problem. My application crashed when running WACK which made it very hard to troubleshoot.
My solution was simply to create a log file. Maybe my code below could be useful. It’s creates a file in the download folder (all applications has write access to that folder). In Template 10 there is a LoggingService which seems to be used a lot. So make sure this service is puts the log to a file. Then it might be easier to solve this. I don’t have access to any ARM device right now so I can’t do it myself.
static IRandomAccessStream LogAccessStream;
static IOutputStream LogOutputStream;
static DataWriter LogDataWriter;
public static void LogToFile(string text = "")
{
if (LogAccessStream == null)
{
string filename = "persitent_log_" + DateTime.Now.ToString("yyyyMMdd_HHmmss");
var newFile = DownloadsFolder.CreateFileAsync(filename + ".txt").AsTask();
newFile.Wait();
var randomFileTask = newFile.Result.OpenAsync(FileAccessMode.ReadWrite).AsTask();
randomFileTask.Wait();
LogAccessStream = randomFileTask.Result;
LogOutputStream = LogAccessStream.GetOutputStreamAt(0);
LogDataWriter = new DataWriter(LogOutputStream);
}
LogDataWriter.WriteString(DateTime.Now.ToString("HHmmss") + " " + text + Environment.NewLine);
LogDataWriter.StoreAsync().AsTask().Wait();
LogOutputStream.FlushAsync().AsTask().Wait();
LogAccessStream.FlushAsync().AsTask().Wait();
}
@bc3tech @JerryNixon As error is reproduced only under certain circumstances (.NET Native compiled, on ARM, when ListView is present on page hosted inside Shell) I think there is probably a race condition and cause for this error is timing issues, maybe order of events. When code is run in a different environment or compiled with different compiler, timeline of events is different and issue does not reproduce. As I realized, code compiled with .NET Native more aggressively uses CPU and often cause UI thread freezes and lags, even when asyn/await pattern is used. Code runs considerably faster and because of it more background and foreground work can be done (and active scrolling of ListView certainly requires work - to measure controls, update layouts - especially when there is complex markup with many UserControls and there are many attached events starting more work after a UserControl loading and unloading, calls to update of many and many bindings which now represented directly in a code when using recommended {x:Bind ...}). Native compiled code runs as fast as system framework code and system code may struggle with user code for a CPU when run on same thread priority. When code is run on a ARM device, CPU nearly have not such power as typical x86 desktop (or Hyper-V hosted emulator running on a same powerful x86) have, and this makes struggle for a CPU power more epic. So, this abuse of a CPU power can cause a timing issues and any timing dependent code with potential race conditions, sensitive to order of events or event timing could probably crash. See, if your event handlers dependent on order of events or code makes assumptions on timing.
@Opiumtm no doubt everything you've said is possible. However you and the others filing & chiming in on this issue keep pointing at Template 10 as the culprit. Hence my suggestion to fork the repo and go for a fix and my comment aiding in targeting any commit(s) that may have served to "expose" this race condition.
@bc3tech
keep pointing at Template 10
It is self evident. See stack trace (absolutely identical for different application and different developers). Crash is reported at a Template10 internal code.
@bc3tech
Hence my suggestion to fork the repo and go for a fix and my comment aiding in targeting any commit(s) that may have served to "expose" this race condition.
We have our applications and this is our primary work. As you can see, we do not have this issue in a testing or proof-of-concept code. We suffer this issue in a production code and this issue make our applications totally unstable and we have tons of complains from an angry users (well, I do not published this version as I tested new version on an actual device before publish and only have complains from an angry users because I do not rolling out a new version with bug fixes, but other developers reported this issue from a production code). Remember that issue appeared not from the start, it appeared out of nowhere with a new build and broken our already nice working code. Also, personally I already wasted many hours to realize what the problem is. I already catch this issue (at first I thought it is a .NET Native toolchain issue and started threads on a Microsoft forum), exhaustively described its symptoms and provided a stack trace (and even an exact Template10 version number) from an actual device to help you fix this outright critical issue. Do you not realize there is critical, top priority issue which prevents use of Template10 in a production code once and for all? Personally I have a bunch of my own bugs to fix in my own code right now. These bugs I can fix. But this issue in a Template10 raises the question to throw away Template10 from my code (and there will be a very hard and long work because Template10 is heavily used in a code) and do not use Template10 because of its practical uselessness and harmfulness because of this issue if it is not fixed in a near future with a top priority. Do you realize this?
I think you should demand a refund, @Opiumtm