Repository navigation
Stack overflow when trying to process ICoreWebView2 within Microsoft.Web.WebView2.Core. #1695
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Actual behavior
Stack overflow when trying to process Microsoft.Web.WebView2.Core.winmd.
Expected behavior
No stack overflow.
Repro steps
-
Create the project:
dotnet new console -n webview2-cswin32 cd webview2-cswin32 dotnet package add Microsoft.Web.WebView2 dotnet package add Microsoft.Windows.CsWin32 -
Update
webview2-cswin32.csprojto add@(ProjectionMetadataWinmd)forMicrosoft.Web.WebView2.Core.winmd:<ItemGroup> <!-- update this, adding %(GeneratePathProperty) --> <PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3967.48" GeneratePathProperty="true" /> </ItemGroup> <ItemGroup> <ProjectionMetadataWinmd Include="$(PkgMicrosoft_Web_WebView2)\lib\Microsoft.Web.WebView2.Core.winmd" /> </ItemGroup>
-
NativeMethods.txtcontent:ICoreWebView2 -
NativeMethods.jsoncontent:{ "$schema": "https://aka.ms/CsWin32.schema.json", "comInterop": { "useComSourceGenerators": true }, "emitSingleFile": false }
Please see this project: webview2-cswin32.zip
It may build the first time:
> dotnet build
…
…\webview2-cswin32\NativeMethods.txt(1,1): warning PInvoke001: Method, type or constant "ICoreWebView2" not found
Subsequent builds will fail:
> donet build
…
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error Stack overflow.
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at System.Runtime.EH.DispatchEx(System.Runtime.StackFrameIterator ByRef, ExInfo ByRef)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.Generator.<IsManagedType>g__Helper|352_0(System.Reflection.Metadata.TypeDefinitionHandle, <>c__DisplayClass352_0 ByRef)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.Generator.IsManagedType(System.Reflection.Metadata.TypeDefinitionHandle)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.Generator.IsManagedType(Microsoft.Windows.CsWin32.TypeHandleInfo)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, GeneratingElement, System.Nullable`1<Microsoft.Windows.CsWin32.QualifiedCustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.Generator.<IsManagedType>g__Helper|352_0(System.Reflection.Metadata.TypeDefinitionHandle, <>c__DisplayClass352_0 ByRef)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.Generator.IsManagedType(System.Reflection.Metadata.TypeDefinitionHandle)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.Generator.IsManagedType(Microsoft.Windows.CsWin32.TypeHandleInfo)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.HandleTypeHandleInfo.ToTypeSyntax(Microsoft.Windows.CsWin32.TypeSyntaxSettings, GeneratingElement, System.Nullable`1<Microsoft.Windows.CsWin32.QualifiedCustomAttributeHandleCollection>, System.Reflection.ParameterAttributes)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.Windows.CsWin32.Generator.<IsManagedType>g__Helper|352_0(System.Reflection.Metadata.TypeDefinitionHandle, <>c__DisplayClass352_0 ByRef)
…
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.CodeAnalysis.CommandLine.BuildClient.Run(System.Collections.Generic.IEnumerable`1<System.String>, Microsoft.CodeAnalysis.CommandLine.RequestLanguage, Microsoft.CodeAnalysis.CommandLine.CompileFunc, Microsoft.CodeAnalysis.CommandLine.CompileOnServerFunc, Microsoft.CodeAnalysis.CommandLine.ICompilerServerLogger)
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.MainCore(System.String[])
C:\Program Files\dotnet\sdk\10.0.203\Roslyn\Microsoft.CSharp.Core.targets(89,5): error at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(System.String[])
Build failed with 764 error(s) and 1 warning(s) in 6.0s
Context
- CsWin32 version: 0.3.275
- Target Framework: net10.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
jonpryor commentedon May 14, 2026
Stack trace of the stack overflow shows
Helper()callingIsManagedType(), which is presumably here:CsWin32/src/Microsoft.Windows.CsWin32/Generator.MetadataHelpers.cs
Line 521 in 2f761a9
jevansaks commentedon May 20, 2026
So that winmd is a WinRT one and CsWin32 is designed only to process Win32Metadata WinMDs. I recognize this is confusing. I can update the tooling to give a better error, but you want to use the CsWinRT projections for that nuget package (which are embedded in that package and you should be getting via nuget package reference already).
FYI Manodasan Wignarajah (@manodasanW) Sergio Pedri (@Sergio0694)
jonpryor commentedon May 20, 2026
Jevan Saks (@jevansaks) wrote:
Indeed it is confusing. (There are multiple types of
.winmdfiles?!)"Obvious question is obvious": is there a Win32Metadata WinMD for WebView2? I don't see one in the Microsoft.Web.Webview2 1.0.3967.48 package, which does have bindings/projections/whatever for .NET Framework + WPF and WinForms in addition to WinRT, and nothing about the path
lib/Microsoft.Web.WebView2.Core.winmdimplies that it's specific to WinRT (especially when compared to e.g.lib/net462/Microsoft.Web.WebView2.Wpf.dll, which is clearly not WinRT).I guess I should look into using microsoft/win32metadata or something to turn
WebView2.tlb/WebView2.idlinto a Win32Metadata.winmdfile?jevansaks commentedon May 20, 2026
So I'm not sure what your goal is, but if you look in the WebView2 nuget package under lib_manual you'll see the "projection" dlls which is where the C#/WinRT versions of these interfaces live and that's the recommended way to call/implement WinRT interfaces such as ICoreWebView2.
Keep in mind ICoreWebView2 is an "exclusive" interface on the CoreWebView2 runtimeclass so that means it's not intended for you to implement, it's only for calling. In C#/WinRT you'd interact with "CoreWebView2" directly.
smourier commentedon May 25, 2026
Jonathan Pryor (@jonpryor) FWIW, I maintain one here https://github.com/smourier/WebView2Aot/tree/main/WebView2Aot.InteropBuilder.Cli (no relation to Winforms/WPF nor to CsWin32) built using this project https://github.com/smourier/webview2-win32md.
littletoxic commentedon Jun 30, 2026
Jonathan Pryor (@jonpryor) The WebView2 "projection" assemblies appear to be the AOT-compatible path. The key property is
WebView2EnableCsWinRTProjection; when enabled, the WebView2 package referencesMicrosoft.Web.WebView2.Core.Projection.dll/WinRT.Runtimeinstead of the classicMicrosoft.Web.WebView2.Core.dllCOM interop path.Here is a small Win32 + WebView2 Native AOT sample using that approach: https://github.com/littletoxic/WebView2Browser
This probably is not a drop-in fix for Uno, since Uno currently has its own
Microsoft.Web.WebView2.Core.*API surface and enabling the projection directly may cause type conflicts. But it seems like a useful direction for a dedicated Win32 Native AOT WebView implementation.