Skip to content

[Problem/Bug]: wv2winrt generates code that does not compile in case of async WinRT methods #5191

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

Open
achipa opened this issue Apr 2, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@achipa
Copy link

achipa commented Apr 2, 2025

What happened?

Followed instructions from https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/winrt-from-js?tabs=winui2%2Cwinrtcsharp#custom-3rd-party-winrt-components to create a UWP project that references a WinRT component via WinRTAdapter. For built-in Windows classes, this seems to work fine, as well as sync versions of 3rd party methods. However, in case of async methods (I'm able to repro it consistently that returns IAsyncAction), the generated code does not compile and returns the following error:

1>D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(943,37): error C2065: 'returnAggregator': undeclared identifier
1>(compiling source file '/Generated%20Files/wv2winrt/HelloComponent.g.cpp')
1>D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(939,67): error C2660: 'winrt::impl::consume_HelloComponent_IClassStaticswinrt::HelloComponent::IClassStatics::SayHelloAsync': function does not take 1 arguments
1>(compiling source file '/Generated%20Files/wv2winrt/HelloComponent.g.cpp')
1> D:\returnaggregatorrepro\WinRTAdapter\Generated Files\winrt\impl\HelloComponent.0.h(87,14):
1> see declaration of 'winrt::impl::consume_HelloComponent_IClassStaticswinrt::HelloComponent::IClassStatics::SayHelloAsync'
1> D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(939,67):
1> while trying to match the argument list '(TOut)'
1> with
1> [
1> TOut=winrt::HelloComponent::SayHelloRequest
1> ]

Looking at the generated code it does seem that for whatever reason returnAggregator is not declared. Peeking at other classes, it does seem to get declared in the preceeding line, i.e.

auto returnAggregator = winrt::make_self<wv2winrt_impl::ReturnAggregator>(
1, !false);

It wasn't apparent where this mismatch comes from, I was only able to replicate with async methods. The workaround would be to use sync method counterparts in the WinRT component, but since there is a compile error already at the binding generation, it's not really a viable alternative.

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

No response

SDK Version

1.0.3124.44

Framework

WinUI2/UWP

Operating System

Windows 11

OS Version

26200.5516

Repro steps

Follow steps from https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/winrt-from-js?tabs=winui2%2Cwinrtcsharp#custom-3rd-party-winrt-components and try to add a component that returns IAsyncAction

Example minimal repro project at https://github.com/achipa/returnaggregatorrepro, which itself is a clone of the Webview2 sample repo with the addition of the WinRT async component and a configured WinRTAdaptor.

Here is the example 3rd party component IDL of the component that causes wv2winrt to fail:

namespace HelloComponent
{
    runtimeclass SayHelloRequest
{
    SayHelloRequest();
    String hello
    {
        get;
        set;
    };
};
runtimeclass SayHelloResponse
{
    SayHelloResponse();
    String world
    {
        get;
        set;
    };
};

    [default_interface]
    runtimeclass Class
    {
        static Windows.Foundation.IAsyncAction SayHelloAsync(SayHelloRequest input, out SayHelloResponse output);
        Class();
    }
}

Steps:

  1. Open https://github.com/achipa/returnaggregatorrepro/tree/main/MyExternalComponent/HelloComponent and build. This will result in a WinRT component (winmd+dll) that has a SayHelloAsync method
  2. Open the main project, MyUWPGetStartApp.sln and build
  3. Error manifests:
Build started at 1:39 PM...
1>------ Build started: Project: WinRTAdapter, Configuration: Debug x64 ------
1>64 bit MIDLRT Processing D:\returnaggregatorrepro\WinRTAdapter\Class.idl
1>Class.idl
1>64 bit MIDLRT Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt\winrtbase.idl
1>winrtbase.idl
1>64 bit MIDLRT Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt\midlbase.idl
1>midlbase.idl
1>Processing WinMD d:\returnaggregatorrepro\myexternalcomponent\hellocomponent\x64\debug\hellocomponent\hellocomponent.winmd
1>Processing WinMD d:\returnaggregatorrepro\packages\microsoft.web.webview2.1.0.3124.44\lib\microsoft.web.webview2.core.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ai.machinelearning.machinelearningcontract\5.0.0.0\windows.ai.machinelearning.machinelearningcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ai.machinelearning.preview.machinelearningpreviewcontract\2.0.0.0\windows.ai.machinelearning.preview.machinelearningpreviewcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.calls.background.callsbackgroundcontract\4.0.0.0\windows.applicationmodel.calls.background.callsbackgroundcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.calls.callsphonecontract\7.0.0.0\windows.applicationmodel.calls.callsphonecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.calls.callsvoipcontract\4.0.0.0\windows.applicationmodel.calls.callsvoipcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.communicationblocking.communicationblockingcontract\2.0.0.0\windows.applicationmodel.communicationblocking.communicationblockingcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.socialinfo.socialinfocontract\2.0.0.0\windows.applicationmodel.socialinfo.socialinfocontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.startuptaskcontract\3.0.0.0\windows.applicationmodel.startuptaskcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.custom.customdevicecontract\1.0.0.0\windows.devices.custom.customdevicecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.deviceslowlevelcontract\3.0.0.0\windows.devices.deviceslowlevelcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.printers.printerscontract\1.0.0.0\windows.devices.printers.printerscontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.smartcards.smartcardbackgroundtriggercontract\3.0.0.0\windows.devices.smartcards.smartcardbackgroundtriggercontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.smartcards.smartcardemulatorcontract\6.0.0.0\windows.devices.smartcards.smartcardemulatorcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.foundation.foundationcontract\4.0.0.0\windows.foundation.foundationcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.foundation.universalapicontract\15.0.0.0\windows.foundation.universalapicontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.gaming.xboxlive.storageapicontract\1.0.0.0\windows.gaming.xboxlive.storageapicontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.graphics.printing3d.printing3dcontract\4.0.0.0\windows.graphics.printing3d.printing3dcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.networking.connectivity.wwancontract\2.0.0.0\windows.networking.connectivity.wwancontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.networking.sockets.controlchanneltriggercontract\3.0.0.0\windows.networking.sockets.controlchanneltriggercontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.security.isolation.isolatedwindowsenvironmentcontract\4.0.0.0\windows.security.isolation.isolatedwindowsenvironmentcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.services.maps.guidancecontract\3.0.0.0\windows.services.maps.guidancecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.services.maps.localsearchcontract\4.0.0.0\windows.services.maps.localsearchcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.services.store.storecontract\4.0.0.0\windows.services.store.storecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.services.targetedcontent.targetedcontentcontract\1.0.0.0\windows.services.targetedcontent.targetedcontentcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.storage.provider.cloudfilescontract\7.0.0.0\windows.storage.provider.cloudfilescontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.profile.profilehardwaretokencontract\1.0.0.0\windows.system.profile.profilehardwaretokencontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.profile.profileretailinfocontract\1.0.0.0\windows.system.profile.profileretailinfocontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.profile.profilesharedmodecontract\2.0.0.0\windows.system.profile.profilesharedmodecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.profile.systemmanufacturers.systemmanufacturerscontract\3.0.0.0\windows.system.profile.systemmanufacturers.systemmanufacturerscontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.systemmanagementcontract\7.0.0.0\windows.system.systemmanagementcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ui.uiautomation.uiautomationcontract\2.0.0.0\windows.ui.uiautomation.uiautomationcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ui.viewmanagement.viewmanagementviewscalingcontract\1.0.0.0\windows.ui.viewmanagement.viewmanagementviewscalingcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ui.xaml.core.direct.xamldirectcontract\5.0.0.0\windows.ui.xaml.core.direct.xamldirectcontract.winmd
1>64 bit MIDLRT Processing D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\DispatchAdapter.idl
1>DispatchAdapter.idl
1>64 bit MIDLRT Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt\winrtbase.idl
1>winrtbase.idl
1>64 bit MIDLRT Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt\midlbase.idl
1>midlbase.idl
1>Processing WinMD d:\returnaggregatorrepro\myexternalcomponent\hellocomponent\x64\debug\hellocomponent\hellocomponent.winmd
1>Processing WinMD d:\returnaggregatorrepro\packages\microsoft.web.webview2.1.0.3124.44\lib\microsoft.web.webview2.core.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ai.machinelearning.machinelearningcontract\5.0.0.0\windows.ai.machinelearning.machinelearningcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ai.machinelearning.preview.machinelearningpreviewcontract\2.0.0.0\windows.ai.machinelearning.preview.machinelearningpreviewcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.calls.background.callsbackgroundcontract\4.0.0.0\windows.applicationmodel.calls.background.callsbackgroundcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.calls.callsphonecontract\7.0.0.0\windows.applicationmodel.calls.callsphonecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.calls.callsvoipcontract\4.0.0.0\windows.applicationmodel.calls.callsvoipcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.communicationblocking.communicationblockingcontract\2.0.0.0\windows.applicationmodel.communicationblocking.communicationblockingcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.socialinfo.socialinfocontract\2.0.0.0\windows.applicationmodel.socialinfo.socialinfocontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.applicationmodel.startuptaskcontract\3.0.0.0\windows.applicationmodel.startuptaskcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.custom.customdevicecontract\1.0.0.0\windows.devices.custom.customdevicecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.deviceslowlevelcontract\3.0.0.0\windows.devices.deviceslowlevelcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.printers.printerscontract\1.0.0.0\windows.devices.printers.printerscontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.smartcards.smartcardbackgroundtriggercontract\3.0.0.0\windows.devices.smartcards.smartcardbackgroundtriggercontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.devices.smartcards.smartcardemulatorcontract\6.0.0.0\windows.devices.smartcards.smartcardemulatorcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.foundation.foundationcontract\4.0.0.0\windows.foundation.foundationcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.foundation.universalapicontract\15.0.0.0\windows.foundation.universalapicontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.gaming.xboxlive.storageapicontract\1.0.0.0\windows.gaming.xboxlive.storageapicontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.graphics.printing3d.printing3dcontract\4.0.0.0\windows.graphics.printing3d.printing3dcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.networking.connectivity.wwancontract\2.0.0.0\windows.networking.connectivity.wwancontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.networking.sockets.controlchanneltriggercontract\3.0.0.0\windows.networking.sockets.controlchanneltriggercontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.security.isolation.isolatedwindowsenvironmentcontract\4.0.0.0\windows.security.isolation.isolatedwindowsenvironmentcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.services.maps.guidancecontract\3.0.0.0\windows.services.maps.guidancecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.services.maps.localsearchcontract\4.0.0.0\windows.services.maps.localsearchcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.services.store.storecontract\4.0.0.0\windows.services.store.storecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.services.targetedcontent.targetedcontentcontract\1.0.0.0\windows.services.targetedcontent.targetedcontentcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.storage.provider.cloudfilescontract\7.0.0.0\windows.storage.provider.cloudfilescontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.profile.profilehardwaretokencontract\1.0.0.0\windows.system.profile.profilehardwaretokencontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.profile.profileretailinfocontract\1.0.0.0\windows.system.profile.profileretailinfocontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.profile.profilesharedmodecontract\2.0.0.0\windows.system.profile.profilesharedmodecontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.profile.systemmanufacturers.systemmanufacturerscontract\3.0.0.0\windows.system.profile.systemmanufacturers.systemmanufacturerscontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.system.systemmanagementcontract\7.0.0.0\windows.system.systemmanagementcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ui.uiautomation.uiautomationcontract\2.0.0.0\windows.ui.uiautomation.uiautomationcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ui.viewmanagement.viewmanagementviewscalingcontract\1.0.0.0\windows.ui.viewmanagement.viewmanagementviewscalingcontract.winmd
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.ui.xaml.core.direct.xamldirectcontract\5.0.0.0\windows.ui.xaml.core.direct.xamldirectcontract.winmd
1>Microsoft(R) Metadata Merge Utility Version 10.0.49.
1>
1>
1>Processing input metadata file x64\Debug\Unmerged\Class.winmd.
1>Processing input metadata file x64\Debug\Unmerged\DispatchAdapter.winmd.
1>Saved output metadata file WinRTAdapter.winmd.
1>Validating metadata file x64\Debug\Merged\WinRTAdapter.winmd.
1>wv2winrt v1.0.3124.44
1>asyncdispatch.cpp
1>DispatchAdapter.cpp
1>dispatchbase.cpp
1>eventargsdispatch.cpp
1>globals.cpp
1>HelloComponent.g.cpp
1>main.cpp
1>returnaggregator.cpp
1>uniquevariant.cpp
1>Windows.Data.g.cpp
1>Windows.Data.Text.g.cpp
1>Windows.Foundation.Collections.g.cpp
1>D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(943,37): error C2065: 'returnAggregator': undeclared identifier
1>(compiling source file '/Generated%20Files/wv2winrt/HelloComponent.g.cpp')
1>D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(939,67): error C2660: 'winrt::impl::consume_HelloComponent_IClassStatics<winrt::HelloComponent::IClassStatics>::SayHelloAsync': function does not take 1 arguments
1>(compiling source file '/Generated%20Files/wv2winrt/HelloComponent.g.cpp')
1>    D:\returnaggregatorrepro\WinRTAdapter\Generated Files\winrt\impl\HelloComponent.0.h(87,14):
1>    see declaration of 'winrt::impl::consume_HelloComponent_IClassStatics<winrt::HelloComponent::IClassStatics>::SayHelloAsync'
1>    D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(939,67):
1>    while trying to match the argument list '(TOut)'
1>        with
1>        [
1>            TOut=winrt::HelloComponent::SayHelloRequest
1>        ]
1>D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(1487,37): error C2065: 'returnAggregator': undeclared identifier
1>(compiling source file '/Generated%20Files/wv2winrt/HelloComponent.g.cpp')
1>D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(1483,85): error C2660: 'winrt::HelloComponent::Class::SayHelloAsync': function does not take 1 arguments
1>(compiling source file '/Generated%20Files/wv2winrt/HelloComponent.g.cpp')
1>    D:\returnaggregatorrepro\WinRTAdapter\Generated Files\winrt\HelloComponent.h(133,24):
1>    see declaration of 'winrt::HelloComponent::Class::SayHelloAsync'
1>    D:\returnaggregatorrepro\WinRTAdapter\Generated Files\wv2winrt\HelloComponent.g.cpp(1483,85):
1>    while trying to match the argument list '(TOut)'
1>        with
1>        [
1>            TOut=winrt::HelloComponent::SayHelloRequest
1>        ]
1>Windows.Foundation.g.cpp
1>Windows.g.cpp
1>Windows.Globalization.g.cpp
1>Windows.Storage.FileProperties.g.cpp
1>Windows.Storage.g.cpp
1>Windows.Storage.Search.g.cpp
1>Windows.Storage.Streams.g.cpp
1>Windows.System.g.cpp
1>Windows.System.UserProfile.g.cpp
1>Done building project "WinRTAdapter.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 1:40 PM and took 47.114 seconds ==========

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

@achipa achipa added the bug Something isn't working label Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants