React-native-windows: Unable to build SimpleHttpModule in C# Example in RNW documentation

Created on 18 Nov 2020  路  9Comments  路  Source: microsoft/react-native-windows

Environment

Run the following in your terminal and copy the results here.

  1. npx react-native --version: 4.13.0
  2. npx react-native info:
    image

Steps To Reproduce

  1. Create a NativeModuleSample following this tutorial https://microsoft.github.io/react-native-windows/docs/native-modules-setup
  2. Implement asyncronous windows following this example https://microsoft.github.io/react-native-windows/docs/native-modules-async#simplehttpmodule-in-c
  3. Both the Example discribed there and the Implementation discribed here (https://github.com/microsoft/react-native-windows-samples/blob/master/samples/NativeModuleSample/csharp/windows/NativeModuleSample/AsyncMethodExamples.cs) should be tested.

    Expected Results

We should be able to build the Native Module Library

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

Example using the Documentation :
SimpleHTTPEx

Example using Githubs Repository
SimpleHTTPEx

Developer First Experience Documentation bug

All 9 comments

@getuliovdmnaweb does the example work if you change Task<string> to IAsyncOperation<string>? This seems like a potential docs issue.

FYI @dannyvv

Hi guys @NickGerleman @dannyvv @chrisglein @jonthysell, I have the same error as @getuliovdmnaweb , but when I create a constant using ReactConstantProvider:

image

This method I copied from that link:
https://github.com/microsoft/react-native-windows/blob/abee26d14b3ffed5210a97283a1353f38b0b1989/vnext/Microsoft.ReactNative.Managed.UnitTests/NativeModuleTest.cs#L498

Isn't this related to the public methods of a Windows Runtime project not being able to expose types that do not inherit from IAsyncInfo?

The NativeModuleSample builds just fine but does not match what's in the docs.

The documentation has been updated to reflect the working sample. Please re-open if the new code doesn't work.

This is the Example:
image
This is the Error:
image

@jonthysell I followed the updated documentation and the same problem still occurs.

@getuliovdmnaweb Can you post a link to your project source? It think this has less to do with the code and more to do with the structure of the solution/project files.

@jonthysell Hello, here is the link to a github repository with the example
https://github.com/getuliovdmnaweb/NativeModuleSample

@jonthysell Hello, here is the link to a github repository with the example
https://github.com/getuliovdmnaweb/NativeModuleSample

As per the docs and samples, please remove public sealed from your module class, so that it defaults to an internal class.

-    public sealed class NativeModuleSample
+    class NativeModuleSample

Making a public WinRT class exports that class externally (to be consumed directly by any WinRT app/lib) however this requires that all public members and methods only use publicly available WinRT types. The types in Microsoft.ReactNative.Managed (such as JSValue and ReactPromise<>) are not publicly available WinRT types, as Microsoft.ReactNative.Managed is a just a Class Library, not a WinRT Library.

The expectation is that your project only exposes the ReactPackageProvider - everything else should be internal types.

Was this page helpful?
0 / 5 - 0 ratings