Repository navigation
Exclude Foundation.Metadata from direct API generation - #1820
Jevan Saks (jevansaks) merged 2 commits into
Conversation
ba0a61b to
389a85c
Compare
|
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. |
There was a problem hiding this comment.
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
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.
|
I assume this is only a problem when these names are requested directly and not when you request the whole namespace? |
|
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. |
|
Thanks Jevan Saks (@jevansaks), appreciate the review and approval. |
|
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? |
|
Merged now |
|
Thanks Jevan Saks (@jevansaks) for getting this merged. |

Fixes #1818.
Direct requests from
NativeMethods.txtcould resolve types fromWindows.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).