-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix ComClassGenerator failure with generic types #122197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 <1571408+jkoritzinsky@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/interop-contrib |
AaronRobinsonMSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
|
/ba-g failures tracked by #122228 |
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.