Describe the bug
I've recently updated to Windows 10 19041.264
, and apparently many .NET Native builds are just flat out broken for me. This includes both the Windows Community Toolkit Sample app (straight from master
, cc. @michael-hawker) as well as my own app Legere (cc. @LanceMcCarthy, since you helped me pinpoint the previous issue in #1286). Some info I managed to gather:
Windows.Foundation.IReference<double>
in the sample app, and SCG.IList<WCT.Uwp.UI.Media.Effects.IPipelineEffect>
in my app.19041
? ๐คทโโ๏ธRelated to this last point, assuming this is the case, I fear that if the W10 VM the Store uses to build the apps with .NET Native gets updated to one with W10 19041, the Store could just recompile the app again (it does so occasionally) and just push that update to all my users, which would then completely trash my app, since on my device it just crashes at startup with the .NET Native build done on W10 19041. Is this fear justified? Is there anything I can do regarding this?
cc. @MichalStrehovsky and @MattWhilden as the two .NET Native experts here ๐
Steps to reproduce the bug
Steps to reproduce the behavior:
master
(ae4000bcc6cd8eb235b9915a811bd5ea1097169a
at the moment).Expected behavior
The app should work just fine.
Screenshots
Version Info
NuGet package version:
Microsoft.UI.Xaml 2.4.2
| Windows 10 version | Saw the problem? |
| :--------------------------------- | :-------------------- |
| Insider Build (19041.264) | Yes |
| November 2019 Update (18363) | |
| May 2019 Update (18362) | |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) | |
| Device form factor | Saw the problem? |
| :-------------------- | :------------------- |
| Desktop | Yes |
| Mobile | |
| Xbox | |
| Surface Hub | |
| IoT | |
Additional context
Just as a test, I tried to checkout my app to a commit from 4+ months ago. I got the same exact crash in the same exact spot, just with a different type (I wasn't using the .Media
package from the toolkit at that time since it didn't exist yet). When I was on 18363
, I could build and run the app just fine with .NET Native, except for that other issue mentioned already in #1286.
Note that the current version of my app targets the 19041 SDK, while the version from 4+ months ago targets the 18362 SDK. Both crash with the same exact error, as mentioned above.
@LanceMcCarthy since you're already familiar with my repo (Legere) as you helped me debug that issue the other time, if you're on 19041
too would you mind if I gave you access to it again to try to see if you can repro the same crash on your end as well?
Just to double check and hopefully gather some more info.
For .NET Native issues I suggest reaching out to dotnetnative at microsoft dot com. This is possibly an issue with the Windows SDK installation, but it's difficult to say.
@Sergio0694 I'll spin up a repro today and report it internally to MSFT SDK team.
My first suspicion is that there is some code being stripped out while compiling, this is the usual reason for MissingMetadataException.
In the meantime, you can avoid this by adding those assemblies to the Runtime Directives list in the Properties/default file. See the example at the top here https://docs.microsoft.com/en-us/dotnet/framework/net-native/runtime-directives-rd-xml-configuration-file-reference
@LanceMcCarthy That's awesome, thanks! I have to say I did try to add some .rd.xml
directives for those missing types, with no luck so far though. I'm sure others with more experience than me might have better results though, I'll try following that link you posted and trying again! ๐
Also I've added you as a collaborator to Legere again in case you need to repro the issue on that solution too. I just find it so weird that the .NET Native build from the Store works fine ๐ค
@MichalStrehovsky Sure, I'll forward this issue and all the details to that address too!
I just wanted to also open a public issue here on GitHub so that other UWP developers stumbling on this as well might see this, instead of having to start investigating the whole thing from scratch.
EDIT: tried in Legere, no luck so far. I'm seeing this type which causes the exception:
System.C.G.IList`1
I've tried with the following directives in my .rd.xml
file:
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<!--
An Assembly element with Name="*Application*" applies to all assemblies in
the application package. The asterisks are not wildcards.
-->
<Assembly Name="*Application*" Dynamic="Required All" />
<!-- System.Collections.Generic.IList`1<Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces.IPipelineEffect> -->
<Namespace Name="System.Collections.Generic" >
<TypeInstantiation Name="IList"
Arguments="Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces.IPipelineEffect"
Serialize="Required All"
Dynamic="Required All"/>
</Namespace>
</Application>
<!-- Microsoft.Toolkit.Uwp.UI.Media package -->
<Library Name="Microsoft.Toolkit.Uwp.UI.Media">
<Namespace Name="Microsoft.Toolkit.Uwp.UI.Media"
Serialize="Required All"
Dynamic="Required All"/>
<Namespace Name="Microsoft.Toolkit.Uwp.UI.Media.Effects"
Serialize="Required All"
Dynamic="Required All"/>
<Namespace Name="Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces"
Serialize="Required All"
Dynamic="Required All"/>
</Library>
</Directives>
But I'm still getting the same error ๐ค
I'm by no means an expert on compiler directives, so I might very well be missing something here.
@Sergio0694 I would try setting the type to the exact one that code uses. Maybe somethign like this:
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Namespace Name="Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces" Serialize="Required Public" />
<TypeInstantiation Name="SCG.IList" Arguments="WCT.Uwp.UI.Media.Effects.IPipelineEffect" Activate="Required Public" />
</Application>
</Directives>
so that we don't clog up this thread, lets move the debugging investigation to a Legere Issue and then come back here with the final solution
Pro Tip for any future visitors, use the MissingMetadataException Troubleshooter to build the Default.rd.xaml file for you!
Wait WHAT! Where has that been this whole time? ๐ฑ
And why is it not listed like everywhere in the UWP docs?
Thank you so much! I'll share those links in the Discord server as well ๐
And why is it not listed like everywhere in the UWP docs?
It's supposed to be linked from the relevant exception messages. Not sure why there's no message on your screenshot - could be yet another bug. It definitely was part of the message when I originally added it for .NET Native 1.0. Those pages represent all the JavaScript I wrote in the past 10 years.
The problem with Windows.Foundation.IReference<double>
is that this is a projected type (maps to Nullable<double>
- that's why I think this is an SDK bug somewhere. I don't expect RD.XML to help with that one and I'm unclear how we can even end up in that situation (I don't know much about WinRT interop).
Possibly related to this, I have another app that is exhibiting a similar behavior:
Together with Legere and the Windows Community Toolkit ( @michael-hawker is that still the case), this seems to be the 3rd app that just has weird issues/crashes with .NET Native on W10 19041. What's more, with this one the crash is there even with the package downloaded from the Store, but again only on Windows 10 19041. Installing and running the app on a PC with W10 18362/18363 works fine.
I was wondering whether there could be some underlying issue of some sort with W10 19041 related to this, or just something in common between all these various issues on 19041? And most importantly, does anyone have any idea for a workaround? I'm at a loss here, both my apps are just a no-go on W10 19041 at the moment and I have no idea why that is or how to solve this ๐
@MichalStrehovsky @MattWhilden This is not really ILC repro material as the .NET Native compiler itself is working fine and the app is built/run correctly, so I'm not sure if there's any repro that I could prepare for you guys that could help? In general, who should I talk to for issues such as these?
๐ฆ FYI @TomMcDon
@Sergio0694 ILCRepros are still quite helpful for app crashes. Being able to rebuild the package and run it lets us help test theories and fixes for runtime issues. ๐
@MattWhilden Ah, awesome then! ๐
Will prepare one (or two) and send them to you guys then ([email protected]
).
EDIT: email sent! ๐
Hey @MichalStrehovsky and @tommcdon, I have some more info on the repro I sent you guys last week. In particular, I was having a ton of crashes with my second app (the one with that exception about IReference<double>
missing, and it took a while but I eventually found a (very ugly) workaround.
I have a separate project which contains two self-contained controls I wrote for my app, which I just reference from my main app, adding the resource dictionary definition in App.xaml
to load the styles from the library, and then using controls from there as usual. This worked 100% fine in Debug, but crashed with .NET Native. Turns out literally just referencing that package causes this crash, even if I don't actually use any code/controls from there at all.
The solution I found was to remove the reference to that project and manually link all the files from that project directly into my main application. Despite the code being exactly the same, this worked just fine with .NET Native. I guess there's some issue loading metadata from secondary projects? ๐คทโโ๏ธ
That said, I'm still left with quite a few (weird) issues, specifically:
KernelBase.dll
or something. This is the _same_ situation I get from my other app Legere: both run fine in Debug, with and without .NET Native, but just fall apart in Release mode.I should also note that one of my apps targets the 19041 SDK, the other targets the 18362 SDK. But they're both showing this weird behavior where they just explode in a local Release build, but work (mostly) fine when downloaded from the Store. Also there are occasional crashes as mentioned before, that only happen with the Store package and that I can't investigate at all right now.
This whole situation is extremely unfortunate, and I hear I'm not the only developer struggling with .NET Native at the moment. Both me and the other devs I talk to are on Windows 10 19041, so somehow it looks like there's _something_ up with .NET Native on this version of Windows? ๐ค
Also I'm lost as to how to investigate those crashes I'm seeing with the Store version, but not in Debug with .NET Native. As long as .NET Native is enabled, shouldn't crashes due to it happen both in Debug and Release? Especially because debugging Release build is not ideal anyway.
Any help here would be much appreciated! ๐
Also please let me know if I should forward this to anyone else, from the SDK team or something.
I just pinged you guys from .NET Native to share the repro and because I've talked to you all in the past already regarding somewhat similar issues, but I'm wondering whether there are other official channels I'm supposed to forward this too as well? Thanks again!
@LanceMcCarthy Just wondering, when/if you had some time to waste, would you be interesting in checking out this second app that has all these other weird issues I listed? I'd be happy to give you access to this repo as well, and if we could confirm that (at least some of) these issues are in fact due to some SDK glitches as @MichalStrehovsky suggested, maybe you could report them as well through your contacts with the SDK team? I personally have no connections in that area ๐
I plan on whittling it down to a bare minimum repro. I haven't had a chance to start it yet because I'm in the middle of recording a video training series with a tight deadline.
Is it possible to have just two projects in a solution. One with the control/component, then the other consuming that control/component and causes the crash?
With that, I can send it right to the team (small repro get the fastest attention because it only takes a minute to spin it up)
@LanceMcCarthy Oh no, absolutely, my ping was just supposed to be an FYI, it really wasn't meant to rush you or anything! Was just curious to know whether this second issue would be something you might be interested in taking a look into and investigating too ๐
I'll get to work on a minimal solution with just those two projects, thanks again! ๐
@LanceMcCarthy Again just FYI (not rushing), I made the repro like you mentioned, with just:
You can find the repro in the repro/sdk-crash-release
branch. The app in master
has exactly the same issue, the only difference is in that branch I've removed all but two projects, and removed unnecessary code (eg. all the MVVM stuff, all the backend code, additional features, etc.).
As mentioned before:
Bonus weird issue: right-clicking the text box in the app to open the context menu will crash the app _only with a package installed from the Store_ (!). Doing exactly the same with a Debug .NET Native build works just fine instead. Really no idea of why that's happening only from the Store ๐คทโโ๏ธ
This is the crash I'm seeing in AppCenter for this case:
Though as mentioned, I can't repro that locally even with .NET Native. I don't know why, but there just seem to be a whole lot of different weird issues going on all at once with this app ๐คฃ
Thanks again, I really appreciate the help!
@Sergio0694 Thanks, I've cloned it and am working on preparing the repro now. I'll open an issue in the repo for any private-project related stuff.
To comment on to your statement about how it work with a Debug .NET Native build, that's still fundamentally different than a Release build. Do a release build and side-load/appinstaller load, I think the same crash should occur.
@michael-hawker I just reproed and reviewed the output, it's definitely happening in Windows,UI.xaml
Release build, signed msix, sideload-installed (Store ingestion doesn't appear to be related)
Event Viewer
Faulting application name: REDACTED.Uwp.exe, version: 1.0.0.0, time stamp: 0x5ee155af
Faulting module name: Windows.UI.Xaml.dll, version: 10.0.18362.815, time stamp: 0x9fa806f2
Exception code: 0xc000027b
Fault offset: 0x0000000000713530
Faulting process id: 0x61ec
Faulting application start time: 0x01d63f71d635f57a
Faulting application path: C:\Program Files\WindowsApps\REDACTED_1.610.1.0_x64__REDACTED\REDACTED.Uwp.exe
Faulting module path: C:\Windows\System32\Windows.UI.Xaml.dll
Report Id: 22e98e81-c491-492c-9b5c-e0806edd6751
Faulting package full name: 77cee5e8-8481-4e69-92bc-31cfb2a6bc2b_1.610.1.0_x64__REDACTED
Faulting package-relative application ID: App
What's strange (or maybe not), the version of Windows.UI.Xaml.dll is 18362 even though the following packages are installed:
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.10</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
<Version>6.1.0-rc1</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Media">
<Version>6.1.0-preview1.2</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.4.2</Version>
</PackageReference>
@Sergio0694 Can you confirm that all of the views have, definitely, replaced the UI components with Microsoft.UI.Xaml
and not are still falling back to Windows.UI.Xaml
?
_Cannot apply a style targeting Windows.UI.Xaml.ContentPresenter with Windows.UI.Xaml.ContentPresenter_ is suspicious, as if they're different types.
@LanceMcCarthy Thank you so much for looking into this!
I'd say the crash coming from WUX is not unsurprising, I'm using Microsoft.UI.Xaml
only in a couple places, specifically for the ItemsRepeater
and TeachingTip
controls, and for a few reveal brushes.
The rest of the app is based on Windows.UI.Xaml
. Also note that WinUI 2.x isn't a 1:1 replacement for WUX, so even if I wanted I wouldn't be able to just replace all the UI components in my app with controls from WinUI, as there's a lot of controls that aren't there at all.
Side question: any clue as to how it's possible that the Release build just crashes at startup, but the one downloaded from the Store works fine instead? I find that very weird ๐ค
Side question n. 2: is that style exception you mentioned the one that happens when trying to open the context menu in the IDE? If that's the one, then yeah that's very weird that it's as if it was trying to load the style for a different control apparently, really not sure where that's coming from.
Especially because again, that part works perfectly fine in Debug instead.
EDIT: just posting here a recap of the various issues I've noticed in the app, as a reference:
IReference<double>
missing metadata error that @MichalStrehovsky commented on)I'm not seeing a startup crash, just the right-click crash. I'm compiling with 19041, but installing on an 18363 machine (which explains why the C:WindowsSystem32Windows.UI.Xaml.dll is v18362 in the crash report).
I don't have 19041 installed, thanks to the Surface update blocks, so I can't much help testing there.
Mmh I think Windows 10 19041 might have something to do about this then.
I just tried to run the app in Release (with the merged resource change you mentioned), and the app is once again just crashing badly right at startup, I'm seeing this (not very useful) exception:
Tried in Debug with .NET Native, and I'm once again back at square one with a startup crash ๐ฅ
It looks like .NET Native on W10 19041 just doesn't like the separate class library with the controls. Which doesn't really make sense, like, why does the installed W10 version even matter? ๐ค
EDIT: also spent 30 minutes loading the symbols for Windows.UI.Xaml.Controls
from the Microsoft symbols server, but didn't get any useful info, apparently those types are not in the symbol files. Not sure how that even works exactly, but VS just left it at that without much other info.
@sergio0694 do you see any spew in the Debug output window that might be helpful?
It looks like a style target type is incorrect (ItemsPresenter
vs ContentPresenter
) I don't have any ideas why that would be yet.
This is probably the culprit
<ItemsControl
ItemsSource="{x:Bind constants:CodeSnippets.All}"
ItemTemplate="{x:Bind CodeSnippetTemplate}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ItemsPresenter">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
@LanceMcCarthy Can confirm that switching that ItemsPresenter
to ContentPresenter
solves the issue! I've uploaded a build to the Store and installed that back, the context menu works great! ๐
So for now there remains the other various startup crashes on 19401.
I also can confirm that fixing the style here didn't solve those startup crashes.
Still, that's progress though, thanks! ๐
This is weird, i have almost exact same exceptions in my framework project.
I-Synergy. Framework (features/dev branch)
I'm pulling my hair out for a week. Tried even to disect the .dmp file without luck.
I have a framework project with an UWP sample which crashes instantly on startup. The exceptions i get are:
Also a strange thing: Commit with tag 2020.1174.1.0 was build successfully several weeks ago, but now i have no way to debug it in native mode.
After investigating more this weekend i tried to push my updates to the Azure build pipeline.
If build 2020.1174.1 was build fine previously, and now it doesn't, maybe this is a local issue.
Strangely, i've got it right. The build has succeeded and the application is runnable just fine.
So why i'm getting these exceptions when i build a native release locally?
Most helpful comment
@Sergio0694 ILCRepros are still quite helpful for app crashes. Being able to rebuild the package and run it lets us help test theories and fixes for runtime issues. ๐