Brainf_ckSharp icon indicating copy to clipboard operation
Brainf_ckSharp copied to clipboard

Repro steps for .NET Native startup crashes

Open Sergio0694 opened this issue 5 years ago โ€ข 16 comments

Hey @alwu-msft, thank you for the help!

As I mentioned in my VS issue, I had two crashes related with .NET Native. The related GitHub issue is this one: https://github.com/microsoft/microsoft-ui-xaml/issues/2545.

Now, the crash in Release is actually vanished somehow and I can't reproduce it anymore not even by checking out to a past commit. The only thing I can think of is that I've updated my PC from 19041.264 to 19041.329, not sure how that might be related though.

I also tried checking out to one of the repro branches I had made for @LanceMcCarthy and I can't repro the Release crash there anymore either, so it does seem to be related to maybe the latest Windows 10 update, or some other thing external to my code and NuGet packages in use ๐Ÿค”

That said, I can still reproduce the crash in Debug with .NET Native though:

  • Clone the repo and switch to repro/sdk-cras-release (the issue appears on master too, this branch is just easier to test though as I've removed a lot of non UI-specific code and projects)
  • Open the solution
  • Right click on Brainf_ckSharp.Uwp > properties > Build
  • Select the Debug x64 config and tick "Enable .NET Native toolchain"
  • Set that project as startup project
  • Run the project

I'm getting a startup crash when doing so, see screen here:

image

Let me know if there's anything I can do to help on my end too, and thanks again! ๐Ÿ˜„

Sergio0694 avatar Jun 16 '20 17:06 Sergio0694

Hey @alwu-msft - just adding some more potentially useful info here as @LanceMcCarthy suggested. I have another app, Legere, which is exhibiting very similar issues. It's closed source too, I can add you as a collaborator too if you want.

That app is crashing at startup with .NET Native no matter what configuration I use.

  1. Release

image

  1. Debug with .NET Native

image

This is from an autogenerated file from the XAML compiler, and @MichalStrehovsky said an issue like this was likely due to an SDK bug, see his comment here: https://github.com/microsoft/microsoft-ui-xaml/issues/2545#issuecomment-633867078.

Hope this helps!

Sergio0694 avatar Jun 16 '20 23:06 Sergio0694

I believe that this is related to .Net Native reflection. The error is happening because you have an implicit style for the Brainf_ckSharp.Uwp.Controls.Ide.Brainf_ckEditBox type, but the metadata provider isn't resolving the type. For Debug builds, we use a reflection-based metadata provider, but for Release builds we generate a table that is used for the lookup, so that's why this works in Release but not Debug. You should be able to work around this by adding the following property to all of your project files: <EnableTypeInfoReflection>false</EnableTypeInfoReflection>

evelynwu-msft avatar Jun 17 '20 20:06 evelynwu-msft

WOW!

Alan, every time I talk to you, I learn something new about how the .NET Native compiler works :)

LanceMcCarthy avatar Jun 17 '20 20:06 LanceMcCarthy

It's just outright avoiding use of .Net Native reflection by the XAML framework; it doesn't do anything to modify the behavior of .Net Native itself. :) I'm checking with one of my co-workers to see if this is a known, wider issue.

evelynwu-msft avatar Jun 17 '20 20:06 evelynwu-msft

@alwu-msft WOW that was super quick, thank you so much! ๐Ÿ˜„

Side note, I also have another app that is crashing both in Debug with .NET Native and in Release, let me see if applying this workaround changes things over there as well, at least in Debug!

Sergio0694 avatar Jun 17 '20 20:06 Sergio0694

@alwu-msft So, I can confirm that fixed the Debug with .NET Native crash in the app! ๐Ÿš€

Potentially related, I have another app that's crashing again in both Release and Debug with .NET Native. Interestingly enough, that app was already using this workaround you suggested (probably someone from the .NET Native team suggested that to me too a few months back, I forgot I had that in that app to be honest).

  1. Release crash:

image

  1. Debug with .NET Native crash:

image

This one in particular is exactly the same as the one I mentioned in the related GitHub issue: https://github.com/microsoft/microsoft-ui-xaml/issues/2545.

Would you be interested in having a look at this too? I can add you as a collaborator if you'd like ๐Ÿ˜Š

Thanks again!

Sergio0694 avatar Jun 17 '20 21:06 Sergio0694

Sure. Just clone the repo, load the solution in VS, and hit F5 to see crash on launch?

evelynwu-msft avatar Jun 17 '20 21:06 evelynwu-msft

@alwu-msft Sent you an invite for https://github.com/Sergio0694/Legere ๐Ÿ‘

And yup, just clone and build + run! You'll need the Multilingual App Toolkit installed to build though! Other than that it should work right out of the box, no additional setup needed.

Sergio0694 avatar Jun 17 '20 21:06 Sergio0694

I can't reproduce your Release crash, although I do get the following exception:

Refit.ApiException: 'Response status code does not indicate success: 401 ().'

 	[Managed to Native Transition]	
>	Refit.dll!Refit.RequestBuilderImplementation.BuildCancellableTaskFuncForMethod.AnonymousMethod__0(System.Net.Http.HttpClient client, System.Threading.CancellationToken ct, object[] paramList) Line 263	C#
 	[Resuming Async Method]	
 	Refit.dll!Refit.RequestBuilderImplementation.BuildCancellableTaskFuncForMethod.AnonymousMethod__0(System.Net.Http.HttpClient client, System.Threading.CancellationToken ct, object[] paramList)	C#
 	[Resuming Async Method]	

followed by a single endlessly spinning progress ring in the app.

As with your other project, it looks like Legere is crashing in Debug builds because one of the referenced libraries (Legere.Markdown) is being compiled with the reflection-based metadata provider, which just doesn't work with .Net Native (but unfortunately, it's not possible for that referenced project to realize that it's going to later be consumed by a project that's using .Net Native).

Moving forward, the simplest workaround is to probably just employ a Directory.Build.props file at least at the .sln level (if not higher in the directory hierarchy) that includes the property <EnableTypeInfoReflection>false</EnableTypeInfoReflection>; that allows you to avoid having to modify every individual project.

evelynwu-msft avatar Jun 18 '20 23:06 evelynwu-msft

Ah, sorry about that! You don't have my access tokens for the various REST services and apparently Unsplash just changed how one of their APIs endpoints worked, so that was causing the crash. I've pushed a quick workaround to master, would you mind fetching the changes (literally just ignored the 401 error it was returning) and trying again?

I did so on my maching and I can confirm I'm still getting this in Release:

image

As for Debug .NET Native, that makes perfect sense now! I have to say that at least, thankfully, that's not really a configuration I'd normally use, I'd either use Debug for quick testing or proper Release with .NET Native for validation before uploading a new package. So personally, I don't mind those issues in Debug .NET Native as much as the Release crash ๐Ÿค”

Thanks again for your time by the way! ๐Ÿ˜„

Sergio0694 avatar Jun 19 '20 00:06 Sergio0694

Hi Sergio, sorry for the radio silence; it's been super busy these last couple weeks. I was able to find a little bit of time to take another look at Legere, but I'm not seeing the crash that you were seeing in Release. If you see it again, I'd recommend saving a crash dump and uploading that along with the app symbols and commit hash to a (private; probably don't want everybody to have access to the dump) cloud share; hopefully that will contain enough information to allow for meaningful postmortem debugging.

evelynwu-msft avatar Jul 02 '20 06:07 evelynwu-msft

Hey @alwu-msft - no worries! Thank you again for taking the time to look into this! ๐Ÿ˜„

It's weird that you're not seeing the crash, I'm still getting that in Release for both my apps actually, Legere and Brainf*ck#. I'll prepare those crash dumps for you, hopefully those will help!

For now I'm just glad I can at least run the app in Debug, and that I don't need .NET Native to create Store packages to upload. As I mentioned, the remote .NET Native build the Store does during certification produces working binaries at least ๐Ÿคทโ€โ™‚๏ธ

Sergio0694 avatar Jul 02 '20 17:07 Sergio0694

Alright I have prepared both dumps, along with the output I'm getting, the commit hashes and all the .pdb files I have.

@alwu-msft I actually plan to make this repo public eventually, so as you mentioned it wouldn't be a good idea to just link the dumps here as they would show up in the comment history - can you share an email/handle I can send the link to? ๐Ÿ˜„

Sergio0694 avatar Jul 02 '20 17:07 Sergio0694

Both of those dumps contain exceptions with the message Non รจ stato possibile caricare il file o l'assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' o una delle relative dipendenze. Impossibile trovare il file specificato.. This doesn't seem related to XAML (which isn't even loaded yet); I'd suggest engaging with the .Net Native team to try to figure out what's going on.

evelynwu-msft avatar Jul 07 '20 01:07 evelynwu-msft

Hey @alwu-msft - thank you again for your time! I see, well then does seem like some sort of issue either with .NET Native as you said, or with the SDK as Lance and Michal suggested. I've sent the two repros to the .NET Native team and also opened a VS feedback item (here), though unfortunately I've received no replies yet. I'll try to ping the VS issue again, hopefully someone will reach out eventually.

Thanks for your help! ๐Ÿ˜„

Sergio0694 avatar Jul 08 '20 10:07 Sergio0694

Closing this as the issue in Brainfk*ck# was resolved, and I also did manage to fix the other issue separately at some point (can't remember exactly what it was, maybe some weird style thingy that was causing a crash). Thanks everyone for the help! ๐Ÿ˜„

Sergio0694 avatar Jan 06 '23 19:01 Sergio0694