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.06k stars 87 forks source link

Generator 'SourceGenerator' failed to generate source. #915

Closed L00pZBreak3r closed 1 year ago

L00pZBreak3r commented 1 year ago

Actual behavior

Generator 'SourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'An item with the same key has already been added.'

Expected behavior

Successful compilation.

Repro steps

  1. NativeMethods.txt content:

    CLSCTX
    CoCreateInstance
    CoTaskMemFree
    ISpellChecker
    ISpellCheckerFactory
    S_FALSE
    S_OK
    SpellCheckerFactory
  2. NativeMethods.json content (if present):

    {
    "$schema": "..\\..\\src\\Microsoft.Windows.CsWin32\\settings.schema.json"
    }
  3. Any of your own code that should be shared?

Context

Marlax0 commented 1 year ago

I had the same problem when I added the Microsoft.Windows.SDK.Win32Metadata package (49.0.21-preview) to my project. Removing it allowed the source generator to work again.

Not sure what the issue is.

AArnott commented 1 year ago

Each major version update of metadata carries with it the potential to break the source generator. We need a source generator update to get you to the latest metadata, evidently.