Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App certification fails with a custom C# native module #4516

Closed
giregk opened this issue Apr 7, 2020 · 19 comments
Closed

App certification fails with a custom C# native module #4516

giregk opened this issue Apr 7, 2020 · 19 comments

Comments

@giregk
Copy link

giregk commented Apr 7, 2020

Environment

  1. react-native -v:
    react-native-cli: 2.0.1
    react-native: 0.61.5

  2. react-native run-windows --info:
    System:
    OS: Windows 10 10.0.18362
    CPU: (4) ia32 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
    Memory: 2.98 GB / 7.92 GB
    Binaries:
    Node: 12.1.0 - C:\Program Files (x86)\nodejs\node.EXE
    Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files (x86)\nodejs\npm.CMD
    npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: ^0.61.5 => 0.61.5
    react-native-windows: 0.61.0 => 0.61.0
    rnpm-plugin-windows: ^0.5.1-0 => 0.5.1-0
    Installed UWP SDKs:
    10.0.14393.0
    10.0.17763.0
    10.0.18362.0

  • Target Platform Version(s): 10.0.18362
  • Target Device(s): Desktop
  • Visual Studio Version: 2019
  • Build Configuration: ReleaseBundle

Steps to Reproduce

  • npx react-native init RNWTestRelease --version ^0.61.5
  • yarn add rnpm-plugin-windows --dev
  • npx react-native windows
  • create a C# custom native module
  • VS2019 > Project > Publish > Associate app with the store ...
  • VS2019 > Project > Publish > Create app packages
    • x86
    • x64
    • ARM

Expected Behavior

The project should pass the certification test.

Actual Behavior

Certification report has an "Supported API test" issue

API _XcptFilter in msvcrt.dll is not supported for this application type. clrcompression.dll calls this API.
API _amsg_exit in msvcrt.dll is not supported for this application type. clrcompression.dll calls this API.
API _except_handler4_common in msvcrt.dll is not supported for this application type. clrcompression.dll calls this API.
API _initterm in msvcrt.dll is not supported for this application type. clrcompression.dll calls this API.
API free in msvcrt.dll is not supported for this application type. clrcompression.dll calls this API.
API malloc in msvcrt.dll is not supported for this application type. clrcompression.dll calls this API.
API memcpy in msvcrt.dll is not supported for this application type. clrcompression.dll calls this API.
API memset in msvcrt.dll is not supported for this application type. clrcompression.dll calls this API.
API ExecuteAssembly in uwphost.dll is not supported for this application type. UWPShim.exe calls this API.
API DllGetActivationFactory in uwphost.dll is not supported for this application type. UWPShim.exe has an export that forwards to this API.

Additional context

The only references to clrcompression are in the build outputs of that custom native C# project. I don't find any references to that in the react-native-windows folder.

I found those links but could not make those fixes work in my projects

I'd like to avoid having to rewrite my module in C++ if possible.

@giregk giregk added the bug label Apr 7, 2020
@ghost ghost added the Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) label Apr 7, 2020
@chrisglein
Copy link
Member

@giregk Based on the breadth of apps hitting this (thank you for the links), this seems like a UWP or Visual Studio issue that isn't specific to RNW. The dotnet/runtime issue seems closest to the source. So you're saying updating that version to 6.2.2 did not resolve this? If not you may want to ping that issue or open a new one. We'd be happy to help find eyeballs to look at this.

Just for context, what is the scope of the C# module you're implementing? Or did this repro on essentially a blank module?

@chrisglein chrisglein added Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) Area: Native Modules and removed Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) labels Apr 9, 2020
@giregk
Copy link
Author

giregk commented Apr 9, 2020

@chrisglein thank you for your answer. My C# project currently uses version 6.2.9 of Microsoft.NETCore.UniversalWindowsPlatform. (The fix in the post is to upgrade to 6.2.2, so I assume that later versions would still be OK, though I haven't tested to use exactly version 6.2.2).

I agree it seems like a UWP or Visual Studio issue, but I thought maybe it could also come from some outdated dependency or specific configuration in react-native-windows. I guess if it doesn't ring a bell to you, it means the answer is elsewhere. I'll keep looking and/or open an new issue and keep you updated.

My module is a bridge to some Windows.Security.Cryptography and Windows.Security.Credentials APIs.
I haven't tried on a blank module. I'll check it.

@ghost ghost added Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) and removed Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) labels Apr 9, 2020
@giregk
Copy link
Author

giregk commented Apr 9, 2020

I'm a beginer with Visual Studio, so I've just understood now what "removing Microsoft.NETCore.Portable.Compatibility" meant! (a suggested fix from one of the above links)

If I open the menu tools > NuGet Package Manager > Manage NuGet Packages for solution > Installed tab then select Microsfot.NETCore.UniversalWindowsPlatform, in the dependencies section, I see this

image

So it looks like my project is using this bad Microsoft.NETCore.Portable.Compatibility.

My question now is do you know how I remove it ?
(Sorry, I know this is not a question specific to RNW, but I think other beginers like me from the JS world could find the answer useful)

====
edit : I tried to check the "remove dependencies" checkbox in the uninstall section and apply the suggested update to 6.2.10 in hope it would do something, but it does not.

@ghost ghost added the Invalid Triage https://github.com/microsoft/react-native-windows/wiki/Triage-Process (label applied by bot) label Apr 9, 2020
@giregk
Copy link
Author

giregk commented Apr 15, 2020

I have made a demo project to test this issue with a virgin project.
All my steps were transcribed in the readme.

So I do get an error with a very simple C# module that exposes the EasClientDeviceInformation method.

I also opened an issue in the dotnet/runtime repo

@giregk
Copy link
Author

giregk commented Apr 16, 2020

I can't wait for this issue to be fixed, so I've rewritten my module in C++ (much simpler than I expected by the way).

I suggest the documentation on C# native modules be updated to highlight the fact that they prevent apps from being published so other developers don't waste time like I did.

@vmoroz vmoroz self-assigned this Apr 24, 2020
@chrisglein
Copy link
Member

@vmoroz you self assigned on this one. Were you thinking this was this at all related to the C# publish issue you were looking at last week? #3838
Do we know if we're adding this dependency or is this some general UWP thing that's not working?

@chrisglein
Copy link
Member

Also, thank you @giregk for trying so hard on this one and doing everything right. Our response time is a bit slow right now :(. I'm glad you're unblocked with the C++ module. We'll get to the bottom of this.

@chrisglein chrisglein added this to the 0.63 (M6) milestone Apr 30, 2020
@chrisglein chrisglein removed Invalid Triage https://github.com/microsoft/react-native-windows/wiki/Triage-Process (label applied by bot) Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) labels Apr 30, 2020
@asklar
Copy link
Member

asklar commented Jun 7, 2020

@giregk sounds like you would run into this if you tried publishing the debug build of the C# app. You can only publish UWP apps to the store that have gone through the .net native toolchain.

@asklar asklar added the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Jul 16, 2020
@ghost ghost added the no-recent-activity Issue/PR has gone stale and may be closed (label applied by bot) label Jul 28, 2020
@ghost
Copy link

ghost commented Jul 28, 2020

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 14 days of this comment.

@giregk
Copy link
Author

giregk commented Jul 28, 2020

Hello @asklar Sorry for my late response, I totally forgot about your comment.

What do you mean by "going through the .net native toolchain" ? Is there a specific action I need to do ? I've reopened my example project and made sure that all projects in the solution are built with the Release config, including the C# one. But I still get the same certification error. I'm not an expert with visual studio at all, so I'm must be doing something wrong.

@ghost ghost added Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) and removed Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) no-recent-activity Issue/PR has gone stale and may be closed (label applied by bot) labels Jul 28, 2020
@asklar
Copy link
Member

asklar commented Jul 28, 2020

@giregk Make sure that you are trying to submit a Release build (not Debug) and that the Use .net native toolchain option is selected for Release:

image

@giregk
Copy link
Author

giregk commented Jul 28, 2020

@asklar I don't have the same configuration. Here is what I see

image

@asklar
Copy link
Member

asklar commented Jul 28, 2020

@giregk I'm looking into this with the project you posted - thanks for that - and I'm able to see the failure from WACK you reported:
image

Stay tuned...

@asklar
Copy link
Member

asklar commented Jul 28, 2020

@giregk I was able to fix the clrcompression failures. The trick is to ensure your native project cross-compiles the C# code onto native since only full native code can be accepted to the store. The cross-compilation / ahead-of-time compilation technology is called .net native. I wrote a sample on how to access a C# UWP component from a C++ UWP app a few months ago, here: https://github.com/asklar/winrtcomponent

Basically what you're missing in your solution is:
a) in your c++ project, add a reference to the nuget package Microsoft.Net.Native.Compiler package
b) add the properties to the project to enable .net native-ization of the code:

  <PropertyGroup>
    <UseDotNetNativeToolchain Condition="'$(Configuration)'=='Release'">true</UseDotNetNativeToolchain>
    <DotNetNativeVersion>2.2.3</DotNetNativeVersion>
  </PropertyGroup>

c) Set your project min version to be >17134

After doing all that I can create a package and the clrcompression WACK failures are fixed.
There are still failures coming from v8jsi but those are ones I fixed in more recent RNW release (I think it was 62? might be newer)

After all this, only the v8jsi failures remain:
image

@asklar
Copy link
Member

asklar commented Jul 29, 2020

@giregk to verify that everything would work without v8JSI, I then went ahead and removed the references to link in v8jsi.dll (which is not needed), rebuilt the package and re-ran WACK and now it passes.
Sent you a PR with the changes, let me know if you're still blocked:

giregk/TestRNWRelease#2

image

@giregk
Copy link
Author

giregk commented Jul 29, 2020

thanks @asklar ! I merged your PR and tried to run the project, but I now get the following error:

Error	C1033	cannot open program database 'C:\Users\...\TestRNWRelease\node_modules\react-native-windows\Microsoft.ReactNative\build\x86\Release\Microsoft.ReactNative\vc141.pdb'	Microsoft.ReactNative	c:\users\...\testrnwrelease\node_modules\react-native-windows\microsoft.reactnative\reacthost\uwpreactinstanceproxy.cpp

I still don't see the 'Compile with .net native toolchain' parameter in the C# project properties.

I unfortunately don't have the time to investigate this further, but I guess I could find the answers on the web now that I know I need to compile the C# code.

The main problem here is probably that my environment is not properly setup for C# projects / I don't have enough background about C# development. Before this project, I had never used Visual Studio and had never used C++, nor C#, nor .NET. The documentation should perhaps guide developpers coming from a js background (like myself) how to setup a visual studio environment from scratch. Especially in preamble of the react-native-windows C# native modules documentation where some knowledge about UWP deployment and C# compiling is required and not explained.

I'll mark this issue as resolved because you were able to fix it. Next time I need to use a C# native module, I'll now where to start from. Again, thank you a lot @asklar for taking the time to look into this.

@giregk giregk closed this as completed Jul 29, 2020
@ghost ghost removed the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Jul 29, 2020
@exotexot
Copy link

exotexot commented Oct 7, 2020

@giregk I was able to fix the clrcompression failures. The trick is to ensure your native project cross-compiles the C# code onto native since only full native code can be accepted to the store. The cross-compilation / ahead-of-time compilation technology is called .net native. I wrote a sample on how to access a C# UWP component from a C++ UWP app a few months ago, here: https://github.com/asklar/winrtcomponent

Basically what you're missing in your solution is:
a) in your c++ project, add a reference to the nuget package Microsoft.Net.Native.Compiler package
b) add the properties to the project to enable .net native-ization of the code:

  <PropertyGroup>
    <UseDotNetNativeToolchain Condition="'$(Configuration)'=='Release'">true</UseDotNetNativeToolchain>
    <DotNetNativeVersion>2.2.3</DotNetNativeVersion>
  </PropertyGroup>

c) Set your project min version to be >17134

After doing all that I can create a package and the clrcompression WACK failures are fixed.
There are still failures coming from v8jsi but those are ones I fixed in more recent RNW release (I think it was 62? might be newer)

After all this, only the v8jsi failures remain:
image

I had the exact same issue and was able to fix it with this solution. This helped me to successfully submit my app submission on the microsoft store. Yet, After applying this fix I cannot run my app in, by clicking the Play Ion (Local Machine) anymore. It crashes with:

Exception thrown at 0x00007FFDE86A3E49 (KernelBase.dll) in cateurope.exe: WinRT originate error - 0x80131522 : 'System.TypeLoadException: Could not load type 'Internal.Runtime.Augments.EnvironmentAugments' from assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
at System.Environment.get_CurrentManagedThreadId()
at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable1 source, Func2 selector)
at Microsoft.ReactNative.Managed.ReactPackageBuilderExtensions.InitAttributedModules()
at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue()'.
onecore\com\combase\winrt\error\restrictederror.cpp(1016)\combase.dll!00007FFDEA34E1B3: (caller: 00007FFDEA2E5EF9) ReturnHr(1) tid(4348) 8007007E The specified module could not be found.

After reverting the changes suggested in this solution. The app starts building just fine. Any ideas?

@ghost ghost added the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Oct 7, 2020
@chrisglein
Copy link
Member

I had the exact same issue and was able to fix it with this solution. This helped me to successfully submit my app submission on the microsoft store. Yet, After applying this fix I cannot run my app in, by clicking the Play Ion (Local Machine) anymore.

@exotexot Ack, that's frustrating. So close to it working! Can you open a new issue that captures your environment so we can help figure this out?
@giregk Did you have the same issue running locally that @exotexot had?

@arsenikstiger
Copy link

C1033

Drop [react-native-windows] folder from [node-modules] and relaunch npm install.

@ghost ghost added the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Jun 26, 2022
@chrisglein chrisglein removed the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants