MicrosoftEdge / MicrosoftEdge/WebView2Feedback

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

Open
#5,191 0 comments 0 reactions 1 assignee View on GitHub

@Navdeep-ss is already working on this.

Since Apr 3, 2025.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.