-
Notifications
You must be signed in to change notification settings - Fork 707
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
C++/WinRT can't easily add a UserControl from a C# Windows Runtime Component #5040
Comments
I've been putting a sample together for the Toolkit, so once I publish that I'll post a link here. This seems mostly like tooling and docs improvements for the future. I'll compare this to WinUI 3 in the future as well to see if the same pitfalls exist. This article was useful as well in resolving references to other NuGet packages. |
@michael-hawker the xamltypeinfo thing is sadly well known and storied. See:
Good catch on the .net native doc, glad to see it fixed. |
Ran into some issues see microsoft/microsoft-ui-xaml#5040 Had to manually add extra header and run in Release mode with .NET Native TODO: Maybe we could run .NET Native in all release configurations to keep some debugging enabled for C++?
The Xaml compiler could make this problem go away by including the headers they depend on and not assuming the project will do it for them. |
agreed but then we run into multiple files including the same set of big headers, so I think that's why XC expects you to add it to PCH instead |
The Xaml compiler can include it regardless to avoid this pit of failure. Developers concerned about build performance are always able to add headers to the PCH (redundantly) to improve their build performance. The latter is a job an app developer is able and willing to do. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Refiled from microsoft/cppwinrt#943 as per @kennykerr
(This issue is about OS UWP, but seems similar/related to discussions around WinUI 3 as well in #4907.)
Was following this guide: https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/use-csharp-component-from-cpp-winrt (still running in Debug though)
But instead of trying to create a regular class, was trying to create a
UserControl
component to use in XAML. That would produce these build errors:In Release with .NET Native there are fewer of these errors at build:
To get the C++/WinRT project to compile I additionally added the Xaml Type Info header to the
MainPage.h
file as well (as mentioned in this Stack Overflow):But then this caused the app to crash at runtime (in debug mode):
I submitted a PR to fix the doc XML here to enable the .NET Native tool chain, and then voila! I could run the app:
So it seems .NET Native is required for this to work? And you have to manually include the Xaml Type Info header currently?
Describe the bug
Steps to reproduce the bug
Steps to reproduce the behavior:
UserControl
to C# ProjectMainPage.h
Expected behavior
Control is usable in Debug or Release mode.
Actual behavior
Need to manually add the extra
_XamlTypeInfo.h
header and run with .NET Native enabled in Release mode.Version Info
NuGet package version: Microsoft.Windows.CppWinRT.2.0.210505.3
No WinUI packages, Just File New Project from C++/WinRT VSIX Templates for Blank App for UWP.
Additional context
Was trying to work on a Sample for CommunityToolkit/WindowsCommunityToolkit#3704 which was also called out here in Issue #4509.
The text was updated successfully, but these errors were encountered: