So you added a new native module or a new method to a module but it isn't working, now what?!
My native method isn't being hit in the VS debugger
If your method isn't being hit in the VS debugger, something is blocking the call due to a mismatch, likely between the expected and actual types that your method takes/returns.
To debug into what is rejecting the call, set a breakpoint in
ReactCommon\react-native-patched\ReactCommon\cxxreact\CxxNativeModule.cpp). This breakpoint is bound to be hit a lot (every time a call to a native method is made), so we want to make sure we only break when our method of interest is involved.
Right-click on the breakpoint to add a Condition. Suppose the method you are interested in catching is called
The conditional breakpoint condition to enter should compare the name of the method to that string:
Compile error 'XamlMetaDataProvider': is not a member of 'winrt::MyModuleName'
Error C2039 'XamlMetaDataProvider': is not a member of 'winrt::MyModuleName' Error C2039 'MyModuleName_XamlTypeInfo': is not a member of 'winrt::MyModuleName'
This can happen if your module includes some XAML markup and you aren't referencing the XAML type information from your C++ app.
To fix this, add the following to your C++ app's
MyNamespaceName will be the same, you can check it in the C# project's properties pane under Root Namespace).
App crashes when trying to load the C# component or instantiate one of its types
Error 0x80131040 "The located assembly’s manifest definition does not match the assembly reference"
C++ apps consuming native modules written in C# need special care. There is a bug in the interop between C# and C++: https://github.com/microsoft/dotnet/issues/1196.
The symptoms are that building the app will work fine but the C++ app will crash at runtime when trying to load the C# module with the error
0x80131040 : The located assembly's manifest definition does not match the assembly reference.
A write-up of the problem can be found here.
As of RNW 0.62, you can enable a
ConsumeCSharpModules property in your C++ app to fix the issue:
- In your .vcxproj file, set this property within
<PropertyGroup Label="ReactNativeWindowsProps"> <ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir> + <ConsumeCSharpModules>true</ConsumeCSharpModules> </PropertyGroup>
If the above workaround doesn't work, you can try two other (older) workarounds:
- Set your C# component's target Windows version to Windows 10 version 1703 (Build 15063) or lower.
- Reference the .NET Native NuGet packages in your C++ app:
- Right click on the app's .vcxproj file → Manage NuGet Packages.
- Search for
Microsoft.Net.Native.Compiler, and install it.
- Then add the following properties to the .vcxproj file:
<PropertyGroup> <UseDotNetNativeToolchain Condition="'$(Configuration)'=='Release'">true</UseDotNetNativeToolchain> <DotNetNativeVersion>2.2.3</DotNetNativeVersion> </PropertyGroup>
For more information and troubleshooting instructions, see the following articles: