Skip to content

Broken code generated due to hardcoded "PInvoke" classname #1696

@icelandcoherence

Description

@icelandcoherence

When setting a custom classname (instead of PInvoke), the generated file Windows.Win32.ICCloseSafeHandle.g.cs contains the line

protected override bool ReleaseHandle() => SomeClass.ICClose((winmdroot.Media.Multimedia.HIC)this.handle) == (global::Windows.Win32.Foundation.LRESULT)PInvoke.ICERR_OK;

This uses PInvoke instead of the classname set in NativeMethods.json, which results in the compilation error The name 'PInvoke' does not exist in the current context. It also uses a hardcoded global::Windows.Win32 which I assume should be winmdroot, although this does not error as those are defined to be the same.

Repro steps

  1. NativeMethods.txt content:
Windows.Win32.Media.Multimedia
  1. NativeMethods.json content:
{
	"$schema": "https://aka.ms/CsWin32.schema.json",
	"className": "SomeClass",
}

Context

  • CsWin32 version: 0.3.275
  • Win32Metadata version: not explicitly set by project
  • Target Framework: net8.0
  • LangVersion: preview

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions