microsoft / cppwinrt

C++/WinRT
MIT License
1.65k stars 238 forks source link

Bug: version 2.0.240111.5 does not work correctly with XAML #1397

Closed YexuanXiao closed 6 months ago

YexuanXiao commented 6 months ago

Version

2.0.240111.5

Summary

After I upgraded the C++/WinRT version, my WinUI3 project failed to build. After switching to the previous version, it built normally.

1>D:\Projects\PlayerWinRT\src\Player.vcxproj : XamlCompiler error WMC1006: Cannot resolve Assembly or Windows Metadata file 'Type universe cannot resolve assembly: Data, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime.'
1>XamlMetaDataProvider.cpp

WindowsAppSDK v1.5.240311000 SDK.BuildTools v10.0.26031-preview

Reproducible example

No response

Expected behavior

No response

Actual behavior

No response

Additional comments

No response

sylveon commented 6 months ago

Try cleaning the project before building after upgrading cppwinrt

YexuanXiao commented 6 months ago

Try cleaning the project before building after upgrading cppwinrt

I manually cleaned up all the generated files, but I still get the same error, with some linking errors. After I switched back to version 2.0.230706.1, the error disappeared and it built successfully.

1>About.xaml.obj : error LNK2019: unresolved external symbol "public: void __cdecl winrt::Player::implementation::AboutT<struct winrt::Player::implementation::About>::InitializeComponent(void)" (?InitializeComponent@?$AboutT@UAbout@implementation@Player@winrt@@$$V@implementation@Player@winrt@@QEAAXXZ) referenced in function "struct winrt::Player::implementation::About * __cdecl winrt::impl::create_and_initialize<struct winrt::Player::implementation::About>(void)" (??$create_and_initialize@UAbout@implementation@Player@winrt@@$$V@impl@winrt@@YAPEAUAbout@implementation@Player@1@XZ)
1>About.xaml.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl winrt::Player::implementation::AboutT<struct winrt::Player::implementation::About>::Connect(int,struct winrt::Windows::Foundation::IInspectable const &)" (?Connect@?$AboutT@UAbout@implementation@Player@winrt@@$$V@implementation@Player@winrt@@UEAAXHAEBUIInspectable@Foundation@Windows@4@@Z)
1>About.xaml.obj : error LNK2001: unresolved external symbol "public: virtual struct winrt::Microsoft::UI::Xaml::Markup::IComponentConnector __cdecl winrt::Player::implementation::AboutT<struct winrt::Player::implementation::About>::GetBindingConnector(int,struct winrt::Windows::Foundation::IInspectable const &)" (?GetBindingConnector@?$AboutT@UAbout@implementation@Player@winrt@@$$V@implementation@Player@winrt@@UEAA?AUIComponentConnector@Markup@Xaml@UI@Microsoft@4@HAEBUIInspectable@Foundation@Windows@4@@Z)
1>Equalizer.xaml.obj : error LNK2019: unresolved external symbol "public: void __cdecl winrt::Player::implementation::EqualizerT<struct winrt::Player::implementation::Equalizer>::InitializeComponent(void)" (?InitializeComponent@?$EqualizerT@UEqualizer@implementation@Player@winrt@@$$V@implementation@Player@winrt@@QEAAXXZ) referenced in function "struct winrt::Player::implementation::Equalizer * __cdecl winrt::impl::create_and_initialize<struct winrt::Player::implementation::Equalizer>(void)" (??$create_and_initialize@UEqualizer@implementation@Player@winrt@@$$V@impl@winrt@@YAPEAUEqualizer@implementation@Player@1@XZ)
1>Equalizer.xaml.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl winrt::Player::implementation::EqualizerT<struct winrt::Player::implementation::Equalizer>::Connect(int,struct winrt::Windows::Foundation::IInspectable const &)" (?Connect@?$EqualizerT@UEqualizer@implementation@Player@winrt@@$$V@implementation@Player@winrt@@UEAAXHAEBUIInspectable@Foundation@Windows@4@@Z)
1>Equalizer.xaml.obj : error LNK2001: unresolved external symbol "public: virtual struct winrt::Microsoft::UI::Xaml::Markup::IComponentConnector __cdecl winrt::Player::implementation::EqualizerT<struct winrt::Player::implementation::Equalizer>::GetBindingConnector(int,struct winrt::Windows::Foundation::IInspectable const &)" (?GetBindingConnector@?$EqualizerT@UEqualizer@implementation@Player@winrt@@$$V@implementation@Player@winrt@@UEAA?AUIComponentConnector@Markup@Xaml@UI@Microsoft@4@HAEBUIInspectable@Foundation@Windows@4@@Z)
1>InfoListItem.xaml.obj : error LNK2019: unresolved external symbol "public:
...

The full MIDL options displayed in VS is

/iid "nul" /env x64 /h "nul" /W1 /I"D:\Projects\PlayerWinRT\src\Controls" /I"D:\Projects\PlayerWinRT\src\ViewModels" /I"D:\Projects\PlayerWinRT\src\Pages" /I"D:\Projects\PlayerWinRT\src\Data" /I"D:\Projects\PlayerWinRT\src\" /char signed /enum_class /tlb "x64\Debug\Player.tlb" /ns_prefix /metadata_dir "C:\Program Files (x86)\Windows Kits\10\References\10.0.22621.0\windows.foundation.foundationcontract\4.0.0.0" /client none /target "NT60" /notlb /nologo /winrt /dlldata "nul" /server none /proxy "nul" /winmd "x64\Debug\Unmerged\%(Filename).winmd

Looks like the custom idl include directories was lost in one of the generation steps.

YexuanXiao commented 6 months ago

I found out that https://github.com/microsoft/cppwinrt/pull/1381 is causing my project to break.

Is this result intentional? @Scottj1s

kennykerr commented 6 months ago

For Xaml issues please use this repo: https://github.com/microsoft/microsoft-ui-xaml

YexuanXiao commented 6 months ago

For Xaml issues please use this repo: https://github.com/microsoft/microsoft-ui-xaml

I’ve found it’s due to a change in the nuget/Microsoft.Windows.CppWinRT.targets file from #1381, so it’s unrelated to the XAML repository.

kennykerr commented 6 months ago

Yes, but that largely serves to support Xaml and the change was made by the same team. I'd love to help but that's your best bet at getting the issue in front of the appropriate developers (they don't monitor this repo).

Scottj1s commented 6 months ago

@YexuanXiao I'd be glad to take a look at a repro project, if you have one

YexuanXiao commented 6 months ago

@YexuanXiao I'd be glad to take a look at a repro project, if you have one

I have a repository that replicates the problem: https://github.com/yexuanXiao/PlayerWinRT

Scottj1s commented 6 months ago

@YexuanXiao thank you for the repro. A fix has been made to CppWinRT: https://github.com/microsoft/cppwinrt/pull/1404

Scottj1s commented 6 months ago

Fix has been published: https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.240405.15