Skip to content

Exclude Foundation.Metadata from direct API generation - #1820

Merged
Jevan Saks (jevansaks) merged 2 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/1818-exclude-metadata-namespace
Oct 6, 2026
Merged

Jevan Saks (jevansaks) merged 2 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/1818-exclude-metadata-namespace

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Fixes #1818.

Direct requests from NativeMethods.txt could resolve types from Windows.Win32.Foundation.Metadata, even though that metadata-only namespace is already excluded from generate-all. Some of those attribute types recurse during managed-type analysis and can overflow the stack.

Reject the metadata decoration namespace at the direct namespace/type generation boundary. Requests now follow the existing no-match warning path instead of attempting to generate those metadata types.

Tests: dotnet test test/Microsoft.Windows.CsWin32.Tests/Microsoft.Windows.CsWin32.Tests.csproj --filter FullyQualifiedName~MetadataDecorationApisAreNotGenerated --no-restore (5 passed).

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Following up after the earlier inactivity. This has been refreshed onto current main and is now 0 behind and mergeable, with the patch unchanged and the rewritten commit SSH-signed. Ready for review when convenient.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The targeted guards address the reported crash, with only a nonblocking diagnostic-suggestion issue remaining.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Prevents direct requests for metadata-only types from triggering recursive analysis and stack overflows, addressing #1818.

Changes:

  • Rejects metadata decoration namespace and type requests through the existing no-match path.
  • Adds five regression cases covering qualified names, unqualified names, and namespace requests.
File Description
test/​Microsoft.Windows.CsWin32.Tests/​GeneratorTests.cs Adds metadata-request rejection tests.
src/​Microsoft.Windows.CsWin32/​Generator.cs Guards direct namespace and type generation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jevansaks

Copy link
Copy Markdown
Member

I assume this is only a problem when these names are requested directly and not when you request the whole namespace?

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Yes — the #1818 failure is from requesting these metadata-decoration names directly (or the exact Foundation.Metadata namespace), not from generating normal API namespaces. Namespace generation only enumerates the requested namespace, and generate-all already skips Foundation.Metadata. I also fixed the diagnostic edge case in 403a0c2 so rejected metadata names are no longer suggested back; the focused metadata tests pass 6/6.

@jevansaks
Jevan Saks (jevansaks) enabled auto-merge (squash) October 6, 2026 18:36
@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Thanks Jevan Saks (@jevansaks), appreciate the review and approval.

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Jevan Saks (@jevansaks) The remaining FullGen-Net10-PreserveSig job ended as cancelled; Validate failed because of that cancellation. Its log shows no reported test assertion failure. My failed-jobs rerun request was denied for lack of repository admin rights. Could you rerun the cancelled shard and dependent validation?

@jevansaks
Jevan Saks (jevansaks) merged commit c93b592 into microsoft:main Oct 6, 2026
28 of 30 checks passed
@jevansaks

Copy link
Copy Markdown
Member

Merged now

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor Author

Thanks Jevan Saks (@jevansaks) for getting this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclude Foundation.Metadata From NativeMethods.txt To Prevent Stack Overflows

3 participants