Skip to content

Stack overflow when trying to process ICoreWebView2 within Microsoft.Web.WebView2.Core. #1695

@jonpryor

Description

@jonpryor

Actual behavior

Stack overflow when trying to process Microsoft.Web.WebView2.Core.winmd.

Expected behavior

No stack overflow.

Repro steps

  1. Create the project:

    dotnet new console -n webview2-cswin32
    cd webview2-cswin32
    dotnet package add Microsoft.Web.WebView2
    dotnet package add Microsoft.Windows.CsWin32
    
  2. Update webview2-cswin32.csproj to add @(ProjectionMetadataWinmd) for Microsoft.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>
  3. NativeMethods.txt content:

    ICoreWebView2
    
  4. NativeMethods.json content:

    {
      "$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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions