Repository navigation
Fix ComClassGenerator failure with generic types - #122197
Merged
Merged
Conversation
Replace < and > with { and } in hint names to avoid ArgumentException when generating source for generic COM classes. Add test case to validate the fix.
Co-authored-by: jkoritzinsky <[email protected]>
Copilot
AI
changed the title
[WIP] Fix COM class source generator failure with type generics
Fix ComClassGenerator failure with generic types
Dec 4, 2025
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
jkoritzinsky
approved these changes
Dec 4, 2025
jkoritzinsky
enabled auto-merge (squash)
December 4, 2025 23:23
jkoritzinsky
disabled auto-merge
December 4, 2025 23:23
jkoritzinsky
enabled auto-merge (squash)
December 4, 2025 23:23
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the ComClassGenerator source generator fails when processing generic COM classes. The issue occurs because Roslyn's AddSource() method rejects hint names containing angle brackets (<, >), which are present in generic type names like ClassFactory<T>. The fix replaces these characters with curly braces ({, }) to create valid hint names while preserving uniqueness.
Key Changes
- Modified hint name generation in
ComClassGeneratorto replace invalid angle bracket characters - Added test coverage for generic COM class generation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ComClassGenerator.cs | Replaces < and > with { and } in hint names before calling AddSource() |
| ComClassGeneratorOutputShape.cs | Adds test case to verify generic COM class generation works correctly |
This was referenced Dec 5, 2025
Open
Member
|
/ba-g failures tracked by #122228 |
Member
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ComClassGenerator fails when processing generic COM classes because hint names contain angle brackets
<>, which are invalid characters for Roslyn source generators. This causes the generator to throwArgumentExceptionand produce no output.Changes:
<and>with{and}in hint names when callingcontext.AddSource()in ComClassGeneratorOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.