microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.05k stars 85 forks source link

PInvoke007: The API "Windows.Win32.Foundation.PCSTR" is ambiguous #969

Closed riverar closed 1 year ago

riverar commented 1 year ago

Actual behavior

To workaround a previously reported issue, I copied/pasted CsWin32 generated output into a separate .cs and compiled it with my app. To resolve PCSTR references, I added Windows.Win32.Foundation.PCSTR to the NativeMethods.txt. This results in the confusing error below:

error PInvoke007: The API "Windows.Win32.Foundation.PCSTR" is ambiguous.
Please specify one of: "Windows.Win32.Foundation.PCSTR", "Windows.Win32.Foundation.PCSTR" or "Windows.Win32.Foundation.PCSTR".

Expected behavior

A clear error or no error at all.

Repro steps

TBD

Context

AArnott commented 1 year ago

Oh dear. That's a terrible experience. It certainly is not supposed to do that.

riverar commented 1 year ago

Is this the expected way to bring in PCSTR? Was hesitant to file a bug as I wasn't sure if I was just doing something iffy.

AArnott commented 1 year ago

Usually PCSTR will be brought in transitively. But if you own the only code that references it, you'll have to request it as you've done here. But PCSTR is a special type that doesn't appear in the metadata. That, and our recent support for multiple metadata files, may be why CsWin32 is misreporting an ambiguity. when you ask for it.