Fix PropertyInjectionSourceGenerator processing static extension method classes #3085
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 PropertyInjectionSourceGenerator in v0.57.63 was incorrectly processing static classes containing extension methods, generating invalid C# syntax that caused compilation errors:
The issue occurred because the generator's
GetClassWithDataSourceProperties
method processed allTypeDeclarationSyntax
nodes but only filtered out abstract classes. Static classes (including extension method classes) were being processed even though they cannot be instantiated and cannot have instance properties that need injection.Root cause: Static extension method classes like this were being processed:
Solution: Added
|| typeSymbol.IsStatic
to the existing filtering condition inPropertyInjectionSourceGenerator.cs
line 36:This minimal change ensures static classes are filtered out just like abstract classes, preventing the generator from attempting to create property injection code for classes that cannot be instantiated.
Fixes #3084.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.