Creating a Native UI Component Crashes On ARM64
Problem Description
When creating a native module with any UI component we receive this error immediately at build time on the ARM64 debug configuration. This error was reproduced while following the instructions for creating a default RNW app with a custom UI module.
System.Reflection.MissingMetadataException: 'Windows.Foundation.IReference1<Double>'`
RN Version: "react-native": "0.72.7", RNW Version "react-native-windows": "0.72.24" ReactNativeNativeModuleSample.csproj Base App csproj
Steps To Reproduce
- Create a base C# RNW project
- Create a new C# native module and auto-link
- Add a UI component
- Run an ARM64 debug build.
Expected Results
Do not recieve the system.reflection error at runtime
CLI version
11.3.10
Environment
System:
OS: Windows 11 10.0.26080
CPU: "(12) x64 Snapdragon® X Elite - X1E78100 - Qualcomm® Oryon⢠CPU"
Memory: 6.45 GB / 15.36 GB
Binaries:
Node:
version: 20.10.0
path: C:\Program Files (x86)\nodejs\node.EXE
Yarn:
version: 1.22.19
path: C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm:
version: 10.2.3
path: C:\Program Files (x86)\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
Versions:
- 10.0.18362.0
- 10.0.19041.0
- 10.0.22000.0
- 10.0.22621.0
IDEs:
Android Studio: Not Found
Visual Studio:
- 17.9.34723.18 (Visual Studio Enterprise 2022)
Languages:
Java: Not Found
Ruby: Not Found
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.7
wanted: 0.72.7
react-native-windows:
installed: 0.72.24
wanted: 0.72.24
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Target Platform Version
10.0.19041
Target Device(s)
No response
Visual Studio Version
Visual Studio 2022
Build Configuration
Debug
Snack, code example, screenshot, or link to a repository
No response
While I'm not sure if there were any changes in 0.73 (or the soon to be released 0.74, probably next week), have you tried updating to a newer version? 0.72 is just outside of the support window: https://microsoft.github.io/react-native-windows/support
The error is still reproducible on latest
Here is the next message when I hit continue
Here is an updated example repo https://github.com/kpete2017/LatestTestProj/tree/main
And new react-native info System: OS: Windows 11 10.0.26080 CPU: "(12) x64 Snapdragon® X Elite - X1E78100 - Qualcomm® Oryon⢠CPU" Memory: 671.25 MB / 15.36 GB Binaries: Node: version: 20.10.0 path: C:\Program Files (x86)\nodejs\node.EXE Yarn: version: 1.22.22 path: C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: version: 10.2.3 path: C:\Program Files (x86)\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: AllowDevelopmentWithoutDevLicense: Enabled Versions: - 10.0.18362.0 - 10.0.19041.0 - 10.0.22000.0 - 10.0.22621.0 IDEs: Android Studio: Not Found Visual Studio: - 17.9.34723.18 (Visual Studio Enterprise 2022) Languages: Java: Not Found Ruby: Not Found npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.74.0-rc.9 wanted: 0.74.0-rc.9 react-native-windows: installed: 0.74.0-preview.4 wanted: 0.74.0-preview.4 npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: Not found newArchEnabled: Not found
Thanks for taking the upgrade to check that out! Sorry it wasn't helpful.
We do have some test coverage of ARM64, but we have less coverage of it as a development environment. Our first guess is that we're missing something in our dependency script specifically for ARM64 dev.
What would help:
- Can you provide a repro repo so we can exactly duplicate your steps?
- Any luck creating a straight UWP C# XAML project and calling the same native APIs? (we want to zero in on what part of the tool chain is failing here)
- If you can provide the text callstack for the above error
No problem. This error doesn't occur in release configurations so it makes sense if something was missed for a development environment.
Here is a repo using RNW latest which contains the problem. https://github.com/kpete2017/LatestTestProj/tree/main
Here is a straight UWP C# Xaml Project calling virtually the same APIs without the RNW UI View Manager which does not error out. They are both targeting 10.0.19041.0 https://github.com/kpete2017/UWP-ARM64-Test
The callstack from when I click "view callstack" appears empty
Here is the error from the debug output
'LatestTestProj.exe' (Win32): Loaded 'C:\Windows\System32\Windows.UI.Xaml.Controls.dll'. Skipped loading symbols. Module is native, and native debugging is currently disabled.
onecore\com\combase\winrtbase\winrtbase.cpp(1230)\combase.dll!00007FFE3F317C88: (caller: 00007FFE1B58C830) ReturnHr(15) tid(415974) 80004002 No such interface supported
Exception thrown: 'System.Reflection.MissingMetadataException' in Unknown Module.
Windows.Foundation.IReference`1<Double>
I went ahead and upgraded the windows version to latest to test and the issue still persists. https://github.com/kpete2017/LatestTestProj/tree/main
No problem. This error doesn't occur in release configurations so it makes sense if something was missed for a development environment.
Here is a repo using RNW latest which contains the problem. https://github.com/kpete2017/LatestTestProj/tree/main
Here is a straight UWP C# Xaml Project calling virtually the same APIs without the RNW UI View Manager which does not error out. They are both targeting 10.0.19041.0 https://github.com/kpete2017/UWP-ARM64-Test
The callstack from when I click "view callstack" appears empty
Here is the error from the debug output 'LatestTestProj.exe' (Win32): Loaded 'C:\Windows\System32\Windows.UI.Xaml.Controls.dll'. Skipped loading symbols. Module is native, and native debugging is currently disabled. onecore\com\combase\winrtbase\winrtbase.cpp(1230)\combase.dll!00007FFE3F317C88: (caller: 00007FFE1B58C830) ReturnHr(15) tid(415974) 80004002 No such interface supported Exception thrown: 'System.Reflection.MissingMetadataException' in Unknown Module. Windows.Foundation.IReference`1
Turns out this also occurs in release configurations with more complicated UI components also. With this we are completely blocked on a native ARM integration.
Are you able to build ARM64 on an x64 machine and then deploy to the ARM64 device?
Yes but it than just crashes immediately on startup instead.
Can you open your project files (csproj) and where it has the configuration section for ARM64 Debug, i.e. <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'"> can you add <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain> (the same way it's set for ARM64 Release).
This problem is in both configurations for us whether it is running dotnet native toolchain or not. Also UseDotNetNativeToolChain has no effect on ARM64 so its running with this set to true by default anyways.
Whenever you turn this option off in visual studio it will always just renable it on a rebuild so I presume its just always enabled.
At least that was my interpretation since it always reset the option on a build when I add this setting through visual studio and I found this issue. https://github.com/dotnet/runtime/issues/54766
It looks like maybe you're hitting an issue with 19041 +UWP + .NET Native not liking library projects that define XAML controls.
Can you try the workaround suggested here: https://github.com/microsoft/microsoft-ui-xaml/issues/2545#issuecomment-1003804397 :
Please try setting EnableTypeInfoReflection to false in each project that uses XAML:
<PropertyGroup>
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>
</PropertyGroup>
We have also tried this as well and it just causes it to error out with a different message. I can send you the .ilc report file if you would like?
It looks like maybe you're hitting an issue with 19041 +UWP + .NET Native not liking library projects that define XAML controls.
Can you try the workaround suggested here: microsoft/microsoft-ui-xaml#2545 (comment) :
Please try setting EnableTypeInfoReflection to false in each project that uses XAML:
<PropertyGroup> <EnableTypeInfoReflection>false</EnableTypeInfoReflection> </PropertyGroup>
We have also updated or windows sdk version to latest and can reproduce this issue.
The Issue also is not reproduced in a default UWP application. Specifically, we only see this when
- We are using react native windows
- We have a custom react native for windows UI component https://microsoft.github.io/react-native-windows/docs/view-managers
No problem. This error doesn't occur in release configurations so it makes sense if something was missed for a development environment.
Here is a repo using RNW latest which contains the problem. https://github.com/kpete2017/LatestTestProj/tree/main
Here is a straight UWP C# Xaml Project calling virtually the same APIs without the RNW UI View Manager which does not error out. They are both targeting 10.0.19041.0 https://github.com/kpete2017/UWP-ARM64-Test
The callstack from when I click "view callstack" appears empty
Here is the error from the debug output 'LatestTestProj.exe' (Win32): Loaded 'C:\Windows\System32\Windows.UI.Xaml.Controls.dll'. Skipped loading symbols. Module is native, and native debugging is currently disabled. onecore\com\combase\winrtbase\winrtbase.cpp(1230)\combase.dll!00007FFE3F317C88: (caller: 00007FFE1B58C830) ReturnHr(15) tid(415974) 80004002 No such interface supported Exception thrown: 'System.Reflection.MissingMetadataException' in Unknown Module. Windows.Foundation.IReference`1
I have an example here where i have a github repo for a UWP app as well as a latest version react native for windows application running ARM64 builds.
The Issue also is not reproduced in a default UWP application. Specifically we only see this when
- We are using react native windows
- We have a custom UI component
It probably doesn't repro in your UWP default application because it's not using WinUI 2 (aka Microsoft.UI.Xaml). RNW and all RNW libs depend on WinUI 2, and it appears there's some issue with .net native on arm64 not liking library projects that rely on WinUI 2.
I know it's not ideal (I assume you're creating a ui component library because you want multiple apps to consume it) but can you try moving the library source (your custom component and viewmanagers) directly into the app project?
We can try, its not ideal and may not work with our project structure at the end of the day but its worth a shot.
We use these UI components as node packages which are consumed by other UI only react native packages. With this in mind its going to be extremely difficult to "un-modularize" everything to fix this.
It probably doesn't repro in your UWP default application because it's not using WinUI 2 (aka Microsoft.UI.Xaml). RNW and all RNW libs depend on WinUI 2, and it appears there's some issue with .net native on arm64 not liking library projects that rely on WinUI 2.
This makes sense, the error is we originally found when using components from legacy WinUI components (Windows.UI.Xaml). But many of our components do not have a WinUI2 equivalent available.
Here is the error from the debug output 'LatestTestProj.exe' (Win32): Loaded 'C:\Windows\System32\Windows.UI.Xaml.Controls.dll'. Skipped loading symbols. Module is native, and native debugging is currently disabled. onecore\com\combase\winrtbase\winrtbase.cpp(1230)\combase.dll!00007FFE3F317C88: (caller: 00007FFE1B58C830) ReturnHr(15) tid(415974) 80004002 No such interface supported Exception thrown: 'System.Reflection.MissingMetadataException' in Unknown Module. Windows.Foundation.IReference`1
Here is the error from the debug output 'LatestTestProj.exe' (Win32): Loaded 'C:\Windows\System32\Windows.UI.Xaml.Controls.dll'. Skipped loading symbols. Module is native, and native debugging is currently disabled. onecore\com\combase\winrtbase\winrtbase.cpp(1230)\combase.dll!00007FFE3F317C88: (caller: 00007FFE1B58C830) ReturnHr(15) tid(415974) 80004002 No such interface supported Exception thrown: 'System.Reflection.MissingMetadataException' in Unknown Module. Windows.Foundation.IReference`1