React-native-windows: SampleAppCS in Release throws exception when clicking "Call SampleModuleCS!"

Created on 7 Jan 2020  路  15Comments  路  Source: microsoft/react-native-windows

This only repros in Release bits, and is most certainly a .Net Native issue.

Call Stack:

System.Private.CoreLib.dll!System.RuntimeExceptionHelpers.FailFast(string message, System.Exception exception, System.RuntimeExceptionHelpers.RhFailFastReason reason, System.IntPtr pExAddress, System.IntPtr pExContext) Line 208 C#
System.Private.CoreLib.dll!System.RuntimeExceptionHelpers.GetRuntimeException(System.Runtime.ExceptionIDs id) Line 74 C#
[External Code]
System.Private.Interop.dll!System.Runtime.InteropServices.McgMarshal.ComRelease(System.IntPtr pComItf) Line 731 C#
System.Private.Interop.dll!System.__ComObject.Cleanup(bool disposing) Line 796 C#
System.Private.Interop.dll!System.RCWFinalizer.~RCWFinalizer() Line 53 C#

Native Modules bug must-have

All 15 comments

Looking into this, it has to do with the new ReactFunctions. The crash is happening when marshaling the Point arguments to call into the JS calcDistance function.

@vmoroz , any ideas?

It's failing at JSValueReader.cs:467: JSValueReaderOf<T>.ReadValue(reader, out T value);

Better callstack:

[External Code]
System.Linq.Expressions.dll!System.Linq.Expressions.Interpreter.LightLambda.RunVoid(object[]   arguments) Line 293
System.Private.CoreLib.dll!System.Func<System.__Canon,   System.__Canon>.Invoke(System.__Canon arg)
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConversionParameters.InvokeObjectArrayDelegate(object[]   arguments) Line 628
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.InvokeTarget(void*   allocatedStackBuffer, ref   Internal.Runtime.TypeLoader.CallConversionParameters conversionParams) Line   852
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int   cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters   context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc   regionDesc) Line 924
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int   cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters   context) Line 903
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr   callerTransitionBlockParam, System.IntPtr callConversionId) Line 480
[External Code]
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.CallDescrWorker(System.IntPtr   callDescr) Line 855
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.InvokeTarget(void*   allocatedStackBuffer, ref   Internal.Runtime.TypeLoader.CallConversionParameters conversionParams) Line   925
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int   cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters   context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc   regionDesc) Line 924
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int   cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters   context) Line 903
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr   callerTransitionBlockParam, System.IntPtr callConversionId) Line 480
[External Code]
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.ReadValueDelegate<System.__UniversalCanon>.Invoke(Microsoft.ReactNative.IJSValueReader   reader, out System.__UniversalCanon value)
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.JSValueReader.ReadValue<SampleLibraryCS.Point>(Microsoft.ReactNative.IJSValueReader   reader) Line 467
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.JSValueReader.ReadArgs<SampleLibraryCS.Point,   SampleLibraryCS.Point>(Microsoft.ReactNative.IJSValueReader reader, out   SampleLibraryCS.Point arg1, out SampleLibraryCS.Point arg2) Line 396
[External Code]
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.ReactMethodInfo.AddToModuleBuilder.AnonymousMethod__0(Microsoft.ReactNative.IJSValueReader   inputReader, Microsoft.ReactNative.IJSValueWriter outputWriter,   Microsoft.ReactNative.MethodResultCallback resolve,   Microsoft.ReactNative.MethodResultCallback reject) Line 228
[External Code]

Does not repro with .Net Native disabled.

Definitely an issue with .NET Native - I can repro it with Debug .Net Native, so hopefully now I'll be able to figure out what's going wrong.

Exception:

Exception thrown at 0x00007FF8907C1571 (mrt100_app.dll) in SampleAppCS.exe: 0xC0000005: Access violation reading location 0x0000000000000002. occurred

Stack:

mrt100_app.dll!RhR2RLazyCheckVectorElemAddr()
mrt100_app.dll!RhTypeCast_IsInstanceOfClass()
mrt100_app.dll!RhTypeCast_IsInstanceOfClass()
mrt100_app.dll!RhTypeCast_IsInstanceOfClass()
mrt100_app.dll!RhTypeCast_CheckArrayStore()
[External Code]
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.InvokeTarget(void* allocatedStackBuffer, ref Internal.Runtime.TypeLoader.CallConversionParameters conversionParams) Line 755
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RawCalliHelper.Call<Internal.Runtime.TypeLoader.CallConversionParameters>(System.IntPtr pfn, void* arg1, ref Internal.Runtime.TypeLoader.CallConversionParameters arg2)
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc regionDesc) Line 922
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context) Line 904
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr callerTransitionBlockParam, System.IntPtr callConversionId) Line 484
[External Code]
mrt100_app.dll!ReturnFromUniversalTransition()
mrt100_app.dll!ReturnFromCallDescrThunk()
[External Code]
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.CallDescrWorker(System.IntPtr callDescr) Line 856
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.InvokeTarget(void* allocatedStackBuffer, ref Internal.Runtime.TypeLoader.CallConversionParameters conversionParams) Line 926
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RawCalliHelper.Call<Internal.Runtime.TypeLoader.CallConversionParameters>(System.IntPtr pfn, void* arg1, ref Internal.Runtime.TypeLoader.CallConversionParameters arg2)
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc regionDesc) Line 922
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context) Line 904
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr callerTransitionBlockParam, System.IntPtr callConversionId) Line 484
[External Code]
mrt100_app.dll!ReturnFromUniversalTransition()
[External Code]
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.ReadValueDelegate<SampleLibraryCS.Point>.Invoke(Microsoft.ReactNative.IJSValueReader reader, out SampleLibraryCS.Point value)
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.JSValueReader.ReadValue<SampleLibraryCS.Point>(Microsoft.ReactNative.IJSValueReader reader) Line 467
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.JSValueReader.ReadArgs<SampleLibraryCS.Point, SampleLibraryCS.Point>(Microsoft.ReactNative.IJSValueReader reader, out SampleLibraryCS.Point arg1, out SampleLibraryCS.Point arg2) Line 396
[External Code]
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.ReactMethodInfo.AddToModuleBuilder.AnonymousMethod__0(Microsoft.ReactNative.IJSValueReader inputReader, Microsoft.ReactNative.IJSValueWriter outputWriter, Microsoft.ReactNative.MethodResultCallback resolve, Microsoft.ReactNative.MethodResultCallback reject) Line 228
[External Code]
Microsoft.ReactNative.dll!winrt::Microsoft::ReactNative::MethodDelegate::operator()(const winrt::Microsoft::ReactNative::IJSValueReader & inputReader, const winrt::Microsoft::ReactNative::IJSValueWriter & outputWriter, const winrt::Microsoft::ReactNative::MethodResultCallback & resolve, const winrt::Microsoft::ReactNative::MethodResultCallback & reject) Line 2546
Microsoft.ReactNative.dll!winrt::Microsoft::ReactNative::ReactModuleBuilder::AddMethod::__l2::<lambda>(folly::dynamic args, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> resolve, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> reject) Line 37
[External Code]
Microsoft.ReactNative.dll!facebook::react::CxxNativeModule::invoke::__l2::<lambda>() Line 144
[External Code]
Microsoft.ReactNative.dll!Mso::React::MessageDispatchQueue::tryFunc(const std::function<void __cdecl(void)> & func) Line 41
Microsoft.ReactNative.dll!Mso::React::MessageDispatchQueue::runOnQueue::__l2::<lambda>() Line 34
Microsoft.ReactNative.dll!Mso::Details::FunctionObjectWrapper<void <lambda>(void),void>::Invoke() Line 165
Microsoft.ReactNative.dll!Mso::QueueService::InvokeTask(Mso::Functor<void __cdecl(void)> && task, std::optional<std::chrono::time_point<std::chrono::steady_clock,std::chrono::duration<__int64,std::ratio<1,1000000000>>>> endTime) Line 208
Microsoft.ReactNative.dll!Mso::ThreadPoolSchedulerWin::WorkCallback(_TP_CALLBACK_INSTANCE * __formal, void * context, _TP_WORK * __formal) Line 89
[External Code]

Callstack with Just My Code disabled:

mrt100_app.dll!RhR2RLazyCheckVectorElemAddr()
mrt100_app.dll!RhTypeCast_IsInstanceOfClass()
mrt100_app.dll!RhTypeCast_IsInstanceOfClass()
mrt100_app.dll!RhTypeCast_IsInstanceOfClass()
mrt100_app.dll!RhTypeCast_CheckArrayStore()
[Managed to Native Transition]
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.InvokeTarget(void* allocatedStackBuffer, ref Internal.Runtime.TypeLoader.CallConversionParameters conversionParams) Line 755
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RawCalliHelper.Call<Internal.Runtime.TypeLoader.CallConversionParameters>(System.IntPtr pfn, void* arg1, ref Internal.Runtime.TypeLoader.CallConversionParameters arg2)
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc regionDesc) Line 922
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context) Line 904
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr callerTransitionBlockParam, System.IntPtr callConversionId) Line 484
[Native to Managed Transition]
mrt100_app.dll!ReturnFromUniversalTransition()
mrt100_app.dll!ReturnFromCallDescrThunk()
[Managed to Native Transition]
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.CallDescrWorker(System.IntPtr callDescr) Line 856
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.InvokeTarget(void* allocatedStackBuffer, ref Internal.Runtime.TypeLoader.CallConversionParameters conversionParams) Line 926
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RawCalliHelper.Call<Internal.Runtime.TypeLoader.CallConversionParameters>(System.IntPtr pfn, void* arg1, ref Internal.Runtime.TypeLoader.CallConversionParameters arg2)
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc regionDesc) Line 922
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context) Line 904
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr callerTransitionBlockParam, System.IntPtr callConversionId) Line 484
[Native to Managed Transition]
mrt100_app.dll!ReturnFromUniversalTransition()
[Managed to Native Transition]
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.ReadValueDelegate<SampleLibraryCS.Point>.Invoke(Microsoft.ReactNative.IJSValueReader reader, out SampleLibraryCS.Point value)
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.JSValueReader.ReadValue<SampleLibraryCS.Point>(Microsoft.ReactNative.IJSValueReader reader) Line 467
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.JSValueReader.ReadArgs<SampleLibraryCS.Point, SampleLibraryCS.Point>(Microsoft.ReactNative.IJSValueReader reader, out SampleLibraryCS.Point arg1, out SampleLibraryCS.Point arg2) Line 396
[Native to Managed Transition]
mrt100_app.dll!ReturnFromCallDescrThunk()
[Managed to Native Transition]
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.CallDescrWorker(System.IntPtr callDescr) Line 856
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.InvokeTarget(void* allocatedStackBuffer, ref Internal.Runtime.TypeLoader.CallConversionParameters conversionParams) Line 926
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RawCalliHelper.Call<Internal.Runtime.TypeLoader.CallConversionParameters>(System.IntPtr pfn, void* arg1, ref Internal.Runtime.TypeLoader.CallConversionParameters arg2)
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc regionDesc) Line 922
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context) Line 904
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr callerTransitionBlockParam, System.IntPtr callConversionId) Line 484
[Native to Managed Transition]
mrt100_app.dll!ReturnFromUniversalTransition()
[Managed to Native Transition]
System.Private.CoreLib.dll!System.InvokeUtils.CallIHelperStaticCall(object thisPtr, System.IntPtr methodToCall, System.IntPtr dynamicInvokeHelperMethod, ref System.InvokeUtils.ArgSetupState argSetupState, bool isTargetThisCall)
System.Private.CoreLib.dll!System.InvokeUtils.CallDynamicInvokeMethod(object thisPtr, System.IntPtr methodToCall, object thisPtrDynamicInvokeMethod, System.IntPtr dynamicInvokeHelperMethod, System.IntPtr dynamicInvokeHelperGenericDictionary, object defaultParametersContext, object[] parameters, bool invokeMethodHelperIsThisCall, bool methodToCallIsThisCall) Line 314
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.CallDynamicInvokeMethod(object thisPtr, System.IntPtr methodToCall, object thisPtrDynamicInvokeMethod, System.IntPtr dynamicInvokeHelperMethod, System.IntPtr dynamicInvokeHelperGenericDictionary, object defaultParametersContext, object[] parameters, bool invokeMethodHelperIsThisCall, bool methodToCallIsThisCall) Line 318
System.Private.Reflection.Execution.dll!Internal.Reflection.Execution.MethodInvokers.StaticMethodInvoker.Invoke(object thisObject, object[] arguments) Line 30
System.Private.Reflection.Core.dll!System.Reflection.Runtime.MethodInfos.RuntimeMethodInfo.Invoke(object obj, object[] parameters) Line 147
System.Linq.Expressions.dll!System.Linq.Expressions.Interpreter.ByRefMethodInfoCallInstruction.Run(System.Linq.Expressions.Interpreter.InterpretedFrame frame) Line 468
System.Linq.Expressions.dll!System.Linq.Expressions.Interpreter.Interpreter.Run(System.Linq.Expressions.Interpreter.InterpretedFrame frame) Line 106
System.Linq.Expressions.dll!System.Linq.Expressions.Interpreter.LightLambda.RunVoid(object[] arguments) Line 298
System.Private.CoreLib.dll!System.Func<object[], object>.Invoke(object[] arg)
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.ReactMethodInfo.ReactMethodImpl.InvokeObjectArrayThunk(object module, Microsoft.ReactNative.IJSValueReader inputReader, Microsoft.ReactNative.IJSValueWriter outputWriter, Microsoft.ReactNative.MethodResultCallback resolve, Microsoft.ReactNative.MethodResultCallback reject)
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.ReactMethodInfo.ReactMethodImpl.Invoke(object module, Microsoft.ReactNative.IJSValueReader inputReader, Microsoft.ReactNative.IJSValueWriter outputWriter, Microsoft.ReactNative.MethodResultCallback resolve, Microsoft.ReactNative.MethodResultCallback reject)
SampleLibraryCS.dll!Microsoft.ReactNative.Managed.ReactMethodInfo.AddToModuleBuilder.AnonymousMethod__0(Microsoft.ReactNative.IJSValueReader inputReader, Microsoft.ReactNative.IJSValueWriter outputWriter, Microsoft.ReactNative.MethodResultCallback resolve, Microsoft.ReactNative.MethodResultCallback reject) Line 228
SampleAppCS.McgInterop.dll!Microsoft.ReactNative.MethodDelegate.Invoke(Microsoft.ReactNative.IJSValueReader inputReader, Microsoft.ReactNative.IJSValueWriter outputWriter, Microsoft.ReactNative.MethodResultCallback resolve, Microsoft.ReactNative.MethodResultCallback reject)
SampleAppCS.McgInterop.dll!Microsoft.ReactNative.MethodDelegate__Impl.Vtbl.Invoke__n(System.IntPtr pComThis, void* unsafe_inputReader, void* unsafe_outputWriter, void* unsafe_resolve, void* unsafe_reject) Line 2398
[Native to Managed Transition]
Microsoft.ReactNative.dll!winrt::Microsoft::ReactNative::MethodDelegate::operator()(const winrt::Microsoft::ReactNative::IJSValueReader & inputReader, const winrt::Microsoft::ReactNative::IJSValueWriter & outputWriter, const winrt::Microsoft::ReactNative::MethodResultCallback & resolve, const winrt::Microsoft::ReactNative::MethodResultCallback & reject) Line 2546
Microsoft.ReactNative.dll!winrt::Microsoft::ReactNative::ReactModuleBuilder::AddMethod::__l2::<lambda>(folly::dynamic args, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> resolve, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> reject) Line 37
Microsoft.ReactNative.dll!std::_Invoker_functor::_Call<void <lambda>(folly::dynamic, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>) &,folly::dynamic,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>>(winrt::Microsoft::ReactNative::ReactModuleBuilder::AddMethod::__l2::void <lambda>(folly::dynamic, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>) & _Obj, folly::dynamic && <_Args_0>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> && <_Args_1>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> && <_Args_2>)
Microsoft.ReactNative.dll!std::invoke<void <lambda>(folly::dynamic, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>) &,folly::dynamic,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>>(winrt::Microsoft::ReactNative::ReactModuleBuilder::AddMethod::__l2::void <lambda>(folly::dynamic, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>) & _Obj, folly::dynamic && <_Args_0>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> && <_Args_1>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> && <_Args_2>)
Microsoft.ReactNative.dll!std::_Invoker_ret<void,1>::_Call<void <lambda>(folly::dynamic, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>) &,folly::dynamic,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>>(winrt::Microsoft::ReactNative::ReactModuleBuilder::AddMethod::__l2::void <lambda>(folly::dynamic, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>) & <_Vals_0>, folly::dynamic && <_Vals_1>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> && <_Vals_2>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> && <_Vals_3>)
Microsoft.ReactNative.dll!std::_Func_impl_no_alloc<void <lambda>(folly::dynamic, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>),void,folly::dynamic,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>>::_Do_call(folly::dynamic && <_Args_0>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> && <_Args_1>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> && <_Args_2>)
Microsoft.ReactNative.dll!std::_Func_class<void,folly::dynamic,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>,std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)>>::operator()(folly::dynamic <_Args_0>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> <_Args_1>, std::function<void __cdecl(std::vector<folly::dynamic,std::allocator<folly::dynamic>>)> <_Args_2>)
Microsoft.ReactNative.dll!facebook::react::CxxNativeModule::invoke::__l2::<lambda>() Line 144
Microsoft.ReactNative.dll!std::_Invoker_functor::_Call<void <lambda>(void) &>(facebook::react::CxxNativeModule::invoke::__l2::void <lambda>(void) & _Obj)
Microsoft.ReactNative.dll!std::invoke<void <lambda>(void) &>(facebook::react::CxxNativeModule::invoke::__l2::void <lambda>(void) & _Obj)
Microsoft.ReactNative.dll!std::_Invoker_ret<void,1>::_Call<void <lambda>(void) &>(facebook::react::CxxNativeModule::invoke::__l2::void <lambda>(void) & <_Vals_0>)
Microsoft.ReactNative.dll!std::_Func_impl_no_alloc<void <lambda>(void),void>::_Do_call()
Microsoft.ReactNative.dll!std::_Func_class<void>::operator()()
Microsoft.ReactNative.dll!Mso::React::MessageDispatchQueue::tryFunc(const std::function<void __cdecl(void)> & func) Line 41
Microsoft.ReactNative.dll!Mso::React::MessageDispatchQueue::runOnQueue::__l2::<lambda>() Line 34
Microsoft.ReactNative.dll!Mso::Details::FunctionObjectWrapper<void <lambda>(void),void>::Invoke() Line 165
Microsoft.ReactNative.dll!Mso::QueueService::InvokeTask(Mso::Functor<void __cdecl(void)> && task, std::optional<std::chrono::time_point<std::chrono::steady_clock,std::chrono::duration<__int64,std::ratio<1,1000000000>>>> endTime) Line 208
Microsoft.ReactNative.dll!Mso::ThreadPoolSchedulerWin::WorkCallback(_TP_CALLBACK_INSTANCE * __formal, void * context, _TP_WORK * __formal) Line 89
ntdll.dll!TppWorkpExecuteCallback()
ntdll.dll!TppWorkerThread()
kernel32.dll!BaseThreadInitThunk()
ntdll.dll!RtlUserThreadStart()

Working with the .Net Native devs internally, getting them a crash dump because it might not be a reflection problem.

Still investigating, tried to update the apps/modules to 16299 in order to consume a newer version of .net native, but the crash still happens.

@jonthysell what are the repro steps? I have never used the .Net Native before.
Our current C# solution generates code at runtime. I wonder if this feature is supported by the.Net Native.

I can repro it by just running the Sample apps in Release mode. I did not realize before that the .Net Native is used. Our reflection-based solution looks wrong for such case. In the short term we hopefully can find a right set of settings for rd.xml file: it is currently missing sample app and library namespaces (adding them does not fix the issue yet). In the long run we will switch to Roslyn-based code generation at compile time.

@vmoroz I've tried everything possible to get the right rd.xml config, but this doesn't look like a reflection metadata issue, since we're not getting the expected metadata exceptions. Even if I add "everything" to rd.xml it still repros.

You can also repro it by just enabling .Net Native in Debug builds, which makes it easier to debug since it's not optimized.

I've given crash dumps with symbols to the .Net Native devs, I'm hoping they can point us in the right direction.

I can, of course, prevent the crash by manually defining the ReadValue method, but that workaround defeats the whole point of providing the reflection:

static partial class JSValueReaderExtensions
{
    public static void ReadValue(this IJSValueReader reader, out Point value)
    {
        int x = 0;
        int y = 0;

        if (reader.ValueType == JSValueType.Object)
        {
            while (reader.GetNextObjectProperty(out string propertyName))
            {
                switch (propertyName)
                {
                    case "x":
                        reader.ReadValue(out x);
                        break;
                    case "y":
                        reader.ReadValue(out y);
                        break;
                }
            }
        }

        value = new Point() { x = x, y = y };
    }
}

I have managed to upgrade the code to use the latest versions of .Net Native and C++/WinRT. It does not fix the .Net Native issue. The new version should enable us using the the Roslyn code generator: https://github.com/aarnott/CodeGeneration.Roslyn . The next steps are:

  • Simplify use of reflection to prepare for Roslyn-based code generation
  • Start using the Roslyn code generation.

I think in the short term it is OK to have the manually written code similar to one above.
Please note that the extensions can be in any class. It must not be JSValueReaderExtensions class. For example:
C# static class MySerializer { public static void ReadValue(this IJSValueReader reader, out Point value) { value = new Point(); if (reader.ValueType == JSValueType.Object) { while (reader.GetNextObjectProperty(out string propertyName)) { switch (propertyName) { case "x": reader.ReadValue(out value.X); break; case "y": reader.ReadValue(out value.Y); break; default: reader.SkipValue(); // We must skip value for correct object reading. break; } } } } }
I will play with the code to see if it can ease the immediate issues.

The bug also causes the managed unit test app to crash (since it uses native modules) with .net native enabled.

I dont think its clear that this baiscally stops any C# app with custom native modules from shipping to the store. (Since .Net Native is a requirement for shipping to the store).

This kind of snuck under the radar.

Adding needs triage so we talk about this....

Was this page helpful?
0 / 5 - 0 ratings