microsoft-ui-xaml: MissingMetadataException with .NET Native on 19041

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:

  • The .NET Native runs fine, but the app crashes at startup.
  • I can’t repro this with a blank UWP app
  • I can repro this both in the Windows Community Toolkit Sample App and in my own app, but the crashes happen with two different types. Specifically, Windows.Foundation.IReference<double> in the sample app, and SCG.IList<WCT.Uwp.UI.Media.Effects.IPipelineEffect> in my app.
  • My app has this crash when I build it with .NET Native on my PC, but if i create a Store package without .NET Native and let the Store build it with .NET Native remotely, then the app package I install from the Store works just fine. I suspect this might be because the Store is using some VMs that have a previous Windows 10 build than 19041? 🤷‍♂️

Important question

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:

  1. Clone the Windows Community Toolkit repo (here), switch to master (ae4000bcc6cd8eb235b9915a811bd5ea1097169a at the moment).
  2. Run the Sample App in Debug x64, observe it works just fine
  3. Right click on the Sample App project > Build > tick “.NET Native toolchain”
  4. Rebuild and run
  5. Observe the crash with that metadata exception (and others as well if you click continue)

Expected behavior

The app should work just fine.

Screenshots

image

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 32 (15 by maintainers)

Most upvoted comments

@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. 😊

@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.

@LanceMcCarthy Again just FYI (not rushing), I made the repro like you mentioned, with just:

  • UWP app project
  • UWP class library with the controls

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:

  • ✅ Debug works fine
  • ❌ Debug .NET Native crashes at startup
  • ❌ Release .NET Native crashes at startup

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:

image

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 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

Greetings!

When trying to compile my project with the .NET Native tool chain I got a similar exception: MissingMetadataException: Windows.Foundation.IReference'1<Double>.

I also agree that adding a reference to a class library that contains user controls causes this exception. I join the question from @ricklee7679. Does anyone else have any ideas on how to fix this? Any help would be appreciated!

Please try setting EnableTypeInfoReflection to false in each project that uses XAML:

<PropertyGroup>
    <EnableTypeInfoReflection>false</EnableTypeInfoReflection>
</PropertyGroup>

Greetings!

When trying to compile my project with the .NET Native tool chain I got a similar exception: MissingMetadataException: Windows.Foundation.IReference'1<Double>.

I also agree that adding a reference to a class library that contains user controls causes this exception. I join the question from @ricklee7679. Does anyone else have any ideas on how to fix this? Any help would be appreciated!

I came across this open issue when searching - MissingMetaDataException: Windows.Foundation.IReference. I got that mentioned exception when debugging a UWP app that uses a in-house UWP class library which defines some custom user controls. It happens only when “Compile with .Net Native tool chain” is checked in the UWP app’s Build properties, under debug mode. I later found adding that class library reference to UWP app can cause the exception, when UWP app does not even use anything in the class library. Here is how this issue can be reproduced by adding a user control class library to the Microsoft’s Xaml control gallery app -

  1. Git clone the Microsoft Gallery app git clone https://github.com/microsoft/Xaml-Controls-Gallery.git

  2. Open the XamlControlsGallery.sln solution file in Visual Studio (mine is Enterprise 2019, but I think other versions should do it too)

  3. Build and Run (hit [F5]) the project with “Debug | x64” build type, and you should see the app runs OK.

  4. Stop debugging the app, now add a new UWP class library to the solution, name the project whatever you like.

  5. Add a user control (or templated control) in the UWP class library by right-clicking on its project, then “Add” -> “New Item” -> enter “User Control” to filter and then add a User Control, accepting everything default.

  6. You may adjust the target Windows version and min version in the UWP class library’s project properties to make them in line with the gallery app’s. One Nuget package may have a different version between the two is “Microsoft.NETCore.UniversalWindowsPlatform”, in that case, use Nuget package manager to update class library’s and bring them in sync, like - image

  7. Add the class library project as a reference to the gallery app project and then debug run the gallery app, the exception happens - image

  8. Uncheck “Compile with .Net Native tool chain” in gallery app’s project Build settings, save and then debug run again, the app runs fine when the setting is OFF. image

The same exception happens when targeting a different platform (x86) in debug mode, or substituting the class library with a “Windows Runtime Component (Universal Windows)” project in hosting the user control. Please let me know if have any inputs or you see this issue is better reported to another place. Thanks!

@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! 🎉

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 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 😕

Possibly related to this, I have another app that is exhibiting a similar behavior:

  • Works perfectly fine in Debug
  • Crashes at startup with .NET Native only on Windows 10 19041

image

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?

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).

Pro Tip for any future visitors, use the MissingMetadataException Troubleshooter to build the Default.rd.xaml file for you!