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

Can't use C# module from C++ on 0.63 #5825

Closed
asklar opened this issue Aug 24, 2020 · 3 comments · Fixed by #5851
Closed

Can't use C# module from C++ on 0.63 #5825

asklar opened this issue Aug 24, 2020 · 3 comments · Fixed by #5851
Assignees
Labels
Blocking High severity blocker issue bug
Milestone

Comments

@asklar
Copy link
Member

asklar commented Aug 24, 2020

@qmatteoq ran into this when trying to update the GeolocationSample to 0.63

I have another question Is there new guidance to follow to reference a native module built in C#? I've noticed that the Microsoft.ReactNative.SharedManaged project is gone and now there's a Microsoft.ReactNative.Managed project, which isn't a shared project but a regular C# one. I've added it in my React Native solution and I've referenced it from my native module. Everything works when it comes to the native module (I can build it just fine), but the main project which references the module doesn't build anymore due to this error:


C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\AppxPackage\Microsoft.AppXPackage.Targets(1361,5): error MSB3816: Loading assembly "C:\GeolocationSample\node_modules\react-native-windows\target\x86\Debug\Microsoft.ReactNative.Managed\Microsoft.ReactNative.Managed\Microsoft.ReactNative.Managed.dll" failed. System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\AppxPackage\Microsoft.AppXPackage.Targets(1361,5): error MSB3816: File name: 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

here is the original version pre 0.63: https://github.com/microsoft/Windows-AppConsult-Samples-UWP/tree/main/GeolocationSample

0.63 attempt: https://microsofteur-my.sharepoint.com/:u:/g/personal/mpagani_microsoft_com/EfR3tQmG2Z1NsEV71ZRp8oEBuGJtwSA20q_j8V7GaJwNgw?e=gs2Idd

@asklar asklar added the bug label Aug 24, 2020
@ghost ghost added the Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) label Aug 24, 2020
@NickGerleman NickGerleman added this to the 0.63 milestone Aug 25, 2020
@NickGerleman
Copy link
Collaborator

Marking for 0.63 since we can scoop this into discussion. @asklar would you be able to add details? Relevant is whether this is a new regression.

@asklar
Copy link
Member Author

asklar commented Aug 25, 2020

Added comments from the Teams thread. @jonthysell mentioned that this is because the cpp project doesn't include references to the microsoft.reactnative.managed.dll which I would expect we wouldn't by default (since you shouldn't need it if you only have C++ native modules), but we should have a documented way for you to consume C# modules from C++)

@NickGerleman NickGerleman added the Blocking High severity blocker issue label Aug 25, 2020
@jonthysell
Copy link
Contributor

I've figured it out, the reason SampleAppCPP works loading SampleLibraryCS - it imports ~40 .Net/UWP/.NetNative targets to make the scenario work, and none of that was added to the CLI template for other apps.

Working on a fix.

@kmelmon kmelmon removed the Needs: Triage 🔍 New issue that needs to be reviewed by the issue management team (label applied by bot) label Aug 27, 2020
jonthysell added a commit that referenced this issue Aug 27, 2020
Right now C++/WinRT apps have a hard time consuming C# WinRT libraries from source. We fixed this in our SampleAppCpp in order to load SampleLibraryCS, but those fixes were not put into the template for the benefit of all apps.

This PR moves the fix into new `CppAppConsumeCSharpModule.(props|targets)` files. Since the fix involves importing a ton of other props/targets, and we don't want to risk breaking existing C++ apps who have no need of consuming C#-based native modules, the changes are behind a new property `ConsumeCSharpModules`.

So if you have a C++/WinRT RNW app (the default) and need to consume C# native module, you can set `<ConsumeCSharpModules>true</ConsumeCSharpModules>` in your app project.

This PR also fixes up the template solution files to include the projects they were missing.

Closes #5825
Closes #4557
jonthysell added a commit to jonthysell/react-native-windows that referenced this issue Aug 27, 2020
…5851)

Right now C++/WinRT apps have a hard time consuming C# WinRT libraries from source. We fixed this in our SampleAppCpp in order to load SampleLibraryCS, but those fixes were not put into the template for the benefit of all apps.

This PR moves the fix into new `CppAppConsumeCSharpModule.(props|targets)` files. Since the fix involves importing a ton of other props/targets, and we don't want to risk breaking existing C++ apps who have no need of consuming C#-based native modules, the changes are behind a new property `ConsumeCSharpModules`.

So if you have a C++/WinRT RNW app (the default) and need to consume C# native module, you can set `<ConsumeCSharpModules>true</ConsumeCSharpModules>` in your app project.

This PR also fixes up the template solution files to include the projects they were missing.

Closes microsoft#5825
Closes microsoft#4557
jonthysell added a commit that referenced this issue Aug 27, 2020
)

This change backports #5851 to 0.63

Original PR: 
Right now C++/WinRT apps have a hard time consuming C# WinRT libraries from source. We fixed this in our SampleAppCpp in order to load SampleLibraryCS, but those fixes were not put into the template for the benefit of all apps.

This PR moves the fix into new `CppAppConsumeCSharpModule.(props|targets)` files. Since the fix involves importing a ton of other props/targets, and we don't want to risk breaking existing C++ apps who have no need of consuming C#-based native modules, the changes are behind a new property `ConsumeCSharpModules`.

So if you have a C++/WinRT RNW app (the default) and need to consume C# native module, you can set `<ConsumeCSharpModules>true</ConsumeCSharpModules>` in your app project.

This PR also fixes up the template solution files to include the projects they were missing.

Closes #5825
Closes #4557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocking High severity blocker issue bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants