Closed AnnYang01 closed 10 months ago
Attach my repro project: \ddfiles3\Team_XAML\User\v-annyang\ThermometerWRC.zip
This might be caused by an old version of the Microsoft.Windows.CppWinRT
package. If your project is using a version from 2022 ("2.0.22*"), I think updating to a more recent version should fix this.
@annyang01 Please reactivate if this still repros with latest version. Thanks!
@ranjeshj @codendone Only C2079 error still exist in Error List after updating the Microsoft.Windows.CppWinRT package to the latest version-2.0.230706.1, I don't have the permission to reactive this issue, please help me reactive it if necessary. C2079 'winrt::impl::producer::vtable' uses undefined struct 'winrt::impl::produce' with [ D=winrt::ThermometerWRC::implementation::UserControl ]
This remaining error sounds like you're missing a #include <winrt/xxx.h>
for the relevant namespace header for that type.
Hopefully adding a missing #include <winrt/xxx.h>
fixed your remaining issue. Re-closing this.
@codendone Could you follow the repro steps and tell me where to insert the code to avoid C2079 error?
In the pch.h file under the MyCppDesktopProject Node, we have added the following line:#include <winrt/ThermometerWRC.h>
, but C2079 error still exist.
@codendone We still failed with same errors on VS 17.9 Preview 3 with the original steps.
After updating all packages to the latest version, errors still exist.
@AnnYang01, the direct cause of the build error is that UserControl.xaml.cpp is missing this:
#include <winrt/Microsoft.UI.Xaml.Markup.h>
You can add that to either UserControl.xaml.cpp or pch.h to resolve the last build error.
However, you'll then have an issue with mismatched target platforms, since your app is Desktop Windows and your ThermometerWRC is Universal Windows. That can be worked around by other means, but ultimately the best thing is to create your WRC project with the "Windows Runtime Component (WinUI3)" template, and not the "Windows Runtime Component (C++/WinRT)" template. That would have avoided all of the preceding build errors and subsequent runtime errors.
@Scottj1s Thank you for your response and providing us with a workaround, but unfortunately it did not get rid of the C2079 error for me, please see the screenshot. We take some time to investigate issue and want to locate which step is causing this issue. thankfully, we can repro this issue using simplified steps, please see Bug 1942026: [Main] Windows Runtime Component (C++/WinRT) failed to build after adding a User Control (WinUI 3) item Not sure if it belongs to WinUI issue or VS. If you have any questions or suggestions, you can add a comment under this bug.
Describe the bug
Build break when C++ Create and reference a WinUI 3 Component library using WinAppSDK 1.4.230913002. Severity Code Description Project File Line Suppression State Details
Steps to reproduce the bug
1.WinAppSdk 1.4.1 Insertion into VS Pipelines - Run main-34126.236 (visualstudio.com) 2.Create a C++ Blank App, Packaged (WinUI3 in Desktop) project, and name it MyCppDesktopProject 3.Create a Windows Runtime Component (C++/WinRT) project, and name it ThermometerWRC
Don't build the project yet.
In Solution Explorer, rename "Class.idl" file to "Thermometer.idl".
Replace the contents of "Thermometer.idl" with the listing below:
Save the file. Build the project.
Right-click the project node and click "Open Folder in File Explorer".
Copy the stub files "Thermometer.h" and "Thermometer.cpp" from the folder
\ThermometerWRC\ThermometerWRC\Generated Files\sources\ and paste into the folder that contains your project files, which is \ThermometerWRC\ThermometerWRC.(Replace the existing files)
Open "Thermometer.h" in VS, replace the content with below code:
Open "Thermometer.cpp" in VS, replace the content with below code:
4.Right click on the MyCppDesktopProject project node and select Add->Reference 5.Click the checkbox for ThermometerWRC and click OK. Your MyCppDesktopProject.vcxproj should have a reference to the ThermometerWRC.vcxproj file. 6.Right click on the ThermometerWRC project node and select Add-> New Item 7.Select User Control (WinUI 3) and press OK. 8.Build the solution. It won't successfully build but that's fine. 9.Replace the existing my_ButtonClick method in UserControl.xaml.cpp with the following
10.In the pch.h file under the MyCppDesktopProject Node, add the following line:
#include <winrt/ThermometerWRC.h>
11.Build and Run the Solution (F5)Expected behavior
No errors.
Screenshots
NuGet package version
WinUI 3 - Windows App SDK 1.4.1: 1.4.230913002
Windows version
Windows 11 (22H2): Build 22621, Windows 10 (21H2): Build 19044
Additional context
No response