Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a Native UI Component Crashes On ARM64 #12970

Open
kpete2017 opened this issue Apr 23, 2024 · 19 comments
Open

Creating a Native UI Component Crashes On ARM64 #12970

kpete2017 opened this issue Apr 23, 2024 · 19 comments
Assignees
Labels
bug External Issue tracked in this repo but change will need to happen in another repo Partner: 3P 3rd party customer asks Scenario: ARM64 Scenario: C# Workstream: Module Support Module developers have the requisite tooling and clear path for adding windows support to modules.
Milestone

Comments

@kpete2017
Copy link

kpete2017 commented Apr 23, 2024

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'`
image

RN Version: "react-native": "0.72.7",
RNW Version "react-native-windows": "0.72.24"
ReactNativeNativeModuleSample.csproj
Base App csproj

Steps To Reproduce

  1. Create a base C# RNW project
  2. Create a new C# native module and auto-link
  3. Add a UI component
  4. 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

@kpete2017 kpete2017 added the bug label Apr 23, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) label Apr 23, 2024
@chrisglein
Copy link
Member

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

@chrisglein chrisglein added Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) Needs: Verify on Latest Version Issue needs to be reproduced on a newer version (label drives bot activity) and removed Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) labels Apr 25, 2024
@kpete2017
Copy link
Author

kpete2017 commented Apr 25, 2024

The error is still reproducible on latest

image

Here is the next message when I hit continue
image

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

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) and removed Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) labels Apr 25, 2024
@chrisglein chrisglein added Scenario: ARM64 and removed Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) Needs: Verify on Latest Version Issue needs to be reproduced on a newer version (label drives bot activity) labels Apr 29, 2024
@chrisglein
Copy link
Member

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

@chrisglein chrisglein added this to the Backlog milestone Apr 29, 2024
@kpete2017
Copy link
Author

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

@kpete2017
Copy link
Author

I went ahead and upgraded the windows version to latest to test and the issue still persists.
https://github.com/kpete2017/LatestTestProj/tree/main

@kpete2017
Copy link
Author

kpete2017 commented Jul 10, 2024

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

@kpete2017 kpete2017 changed the title Creating a Native UI Component Causes a Missing Metadata Exception on ARM64 Machines Creating a Native UI Component Crashes On ARM64 Jul 15, 2024
@chrisglein chrisglein added Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) Partner: 3P 3rd party customer asks Scenario: C# labels Jul 25, 2024
@chrisglein chrisglein modified the milestones: Backlog, Next Jul 25, 2024
@chrisglein chrisglein removed the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Jul 29, 2024
@jonthysell
Copy link
Contributor

Are you able to build ARM64 on an x64 machine and then deploy to the ARM64 device?

@kpete2017
Copy link
Author

Yes but it than just crashes immediately on startup instead.

@jonthysell
Copy link
Contributor

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

@kpete2017
Copy link
Author

kpete2017 commented Jul 29, 2024

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

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.
dotnet/runtime#54766

@jonthysell
Copy link
Contributor

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>

@kpete2017
Copy link
Author

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?

@kpete2017
Copy link
Author

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.

@kpete2017
Copy link
Author

kpete2017 commented Jul 29, 2024

The Issue also is not reproduced in a default UWP application. Specifically, we only see this when

  1. We are using react native windows
  2. We have a custom react native for windows UI component
    https://microsoft.github.io/react-native-windows/docs/view-managers

@kpete2017
Copy link
Author

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

@jonthysell
Copy link
Contributor

The Issue also is not reproduced in a default UWP application. Specifically we only see this when

  1. We are using react native windows
  2. 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?

@kpete2017
Copy link
Author

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.

@kpete2017
Copy link
Author

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.

@kpete2017
Copy link
Author

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.

@chrisglein chrisglein added the External Issue tracked in this repo but change will need to happen in another repo label Jul 29, 2024
@jonthysell jonthysell self-assigned this Aug 14, 2024
@chiaramooney chiaramooney added the Workstream: Module Support Module developers have the requisite tooling and clear path for adding windows support to modules. label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug External Issue tracked in this repo but change will need to happen in another repo Partner: 3P 3rd party customer asks Scenario: ARM64 Scenario: C# Workstream: Module Support Module developers have the requisite tooling and clear path for adding windows support to modules.
Projects
None yet
Development

No branches or pull requests

4 participants