Native side 'Cannot generate ReadValue delegate' for native module method with a two-argument callback
Problem Description
Native side runtime throws a 'Cannot generate ReadValue delegate for type System.Action`2[System.String,System.String]' exception when JS calls a native module method with a two-argument callback. The same method is successfully called when callback has only one argument.
Native Side Exception happens before the execution flow reaches the method called inside Native Module:
System.Exception HResult=0x80131500 Message=Cannot generate ReadValue delegate for type System.Action'2[System.String,System.String] Source=Microsoft.ReactNative.Managed StackTrace: at Microsoft.ReactNative.Managed.JSValueReaderGenerator.GenerateReadValueDelegate(Type valueType) in F:\RNWPlayground\node_modules\react-native-windows\Microsoft.ReactNative.Managed\JSValueReaderGenerator.cs:line 161 at Microsoft.ReactNative.Managed.JSValueReader.<>c__DisplayClass67_0.<GetReadValueDelegate>b__0() in F:\RNWPlayground\node_modules\react-native-windows\Microsoft.ReactNative.Managed\JSValueReader.cs:line 503 at System.Lazy'1.ViaFactory(LazyThreadSafetyMode mode)
Steps To Reproduce
Call a Native Module method that has a callback with more than one argument.
Expected Results
Successful call :P
CLI version
7.0.4
Environment
System:
OS: Windows 10 10.0.19044
CPU: (16) x64 Intel(R) Xeon(R) W-2145 CPU @ 3.70GHz
Memory: 44.93 GB / 63.65 GB
Binaries:
Node: 16.16.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
AllowAllTrustedApps: Enabled
Versions: 10.0.16299.0, 10.0.17134.0, 10.0.17763.0, 10.0.18362.0, 10.0.19041.0, 10.0.22000.0
IDEs:
Android Studio: Not Found
Visual Studio: 16.11.32802.440 (Visual Studio Enterprise 2019)
Languages:
Java: 1.8.0_302 - C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot\bin\javac.EXE
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: ^0.68.0 => 0.68.3
react-native-windows: 0.68.15 => 0.68.15
npmGlobalPackages:
*react-native*: Not Found
Target Platform Version
10.0.19041
Target Device(s)
Desktop
Visual Studio Version
Visual Studio 2019
Build Configuration
Debug
Snack, code example, screenshot, or link to a repository
No response
@vmoroz fyi
Looks to be a C# issue. Would be helpful to see your sample code so we know if there's something in the codegen here.
Hey folks, Thank you for looking into this one.
Do you need anything else but the native module causing the issue? LPCHostAppData.txt
@iuriT , thank you for the sample! I will have a look at this issue tomorrow 9/30. ~~What version of RNW do you use? We will need to backport the fix to that version.~~ Never mind - I see that it is 0.68.
I hope I am not breaking any protocol or privacy policy by saying this, but please let me know if a direct communication channel in Teams might help you, I'm from MS.
hey @iuriT could you please link your github acount? https://repos.opensource.microsoft.com/link
Just a quick update while I am still working on it. The part that looks suspicious is that:
- We have a unit test that has a callback with multiple parameters, and it passes.
- We switched at some point from the reflection code to the Roslyn code gen.
- The bug seems to happen in the old reflection code which we are not maintaining and plan to delete. @iuriT, could you check that your project uses the Microsoft.ReactNative.Managed.CodeGen project.
I am going to implement a new set of C# integration tests to investigate C# related issues end-to-end. At this point I suspect that the issue is with your project configuration, but I cannot prove it until I see it working in the integration tests.
Yeap, there is a ref to Microsoft.ReactNative.Managed.CodeGen. Let me know if you need me to pack up the whole thing and share it with you to help.
Yeap, there is a ref to Microsoft.ReactNative.Managed.CodeGen. Let me know if you need me to pack up the whole thing and share it with you to help.
No, nothing is needed at this point - I am still struggling to implement C# integration tests.