microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.24k stars 1.13k forks source link

Unsafe code in C# results in "ReactNativeCodeGen.rsp exited with code 1" #13491

Open 0x4741 opened 1 month ago

0x4741 commented 1 month ago

Problem Description

Using any unsafe code in native modules causes the project to fail when running in a debug configuration

Steps To Reproduce

  1. Allow unsafe blocks in csproj.
  2. Declare any type of unsafe code, blocks or methods.
  3. Run.

Expected Results

No response

CLI version

13.6.9

Environment

System:
  OS: Windows 10 10.0.19045
  CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  Memory: 2.10 GB / 7.73 GB
Binaries:
  Node:
    version: 20.15.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.22
    path: C:\Program Files (x86)\Yarn\bin\yarn.CMD
  npm:
    version: 10.8.2
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    AllowAllTrustedApps: Enabled
    Versions:
      - 10.0.19041.0
      - 10.0.22621.0
IDEs:
  Android Studio: Not Found
  Visual Studio:
    - 17.10.35027.167 (Visual Studio Community 2022)
Languages:
  Java: Not Found
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 13.6.9
    wanted: ^13.6.2
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.3
    wanted: ^0.74.3
  react-native-windows:
    installed: 0.74.11
    wanted: 0.74.11
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Community Modules

@react-native-community/cli

Target Platform Version

None

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

Debug

Snack, code example, screenshot, or link to a repository

Here is an example from React-native-windows-samples that uses NativeModuleSample. Same result on both Windows 10 and 11.

Message when using --logging: "C:\Users\User\Documents\AwesomeProject\node_modules\react-native-windows\target\x64\Debug\Microsoft.ReactNative.Managed.CodeGen\publish\Microsoft.ReactNative.Managed.CodeGen.exe

@C\Users\User\Documents\AwesomeProject\windows\AwesomeProject\obj\x64\Debug\awesomeproject.ReactNativeCodeGenawesomeproject.ReactNativeCodeGen.rsp" exited with code 1.

chrisglein commented 1 month ago

Can you help us find the breaking point in your example? I could only find this: https://github.com/0x4741/-ReactNativeWindows-UnsafeBug/blob/d7dfb5886f4a5dca5823538622a1c5f75e702974/windows/NativeModuleSample/DataMarshallingExamples.cs#L207 Which isn't an attributed method, so I wouldn't expect it to hit by the RN native modules. Or are you saying just by having any unsafe code in there, it fails?

Is there more to the build log than the snippet you provided above that might be helpful?

Out of curiosity, where are you planning on using unsafe code in your C# module?

0x4741 commented 1 month ago

Yes, having any unsafe code, even if it is not used, causes it to fail. I am planning to use unsafe code in some native modules needed for a DLL.