Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 10, 2025

The PropertyInjectionSourceGenerator in v0.57.63 was incorrectly processing static classes containing extension methods, generating invalid C# syntax that caused compilation errors:

CS1026: ) expected
CS1002: ; expected  
CS1513: } expected
The type name 'extension' does not exist in the type 'PhoneNumberFixtures'

The issue occurred because the generator's GetClassWithDataSourceProperties method processed all TypeDeclarationSyntax 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:

public static class PhoneNumberFixtures
{
    public static PhoneNumber CreateValid(this PhoneNumber phoneNumber)
    {
        return new PhoneNumber("123-456-7890");
    }
}

Solution: Added || typeSymbol.IsStatic to the existing filtering condition in PropertyInjectionSourceGenerator.cs line 36:

// Before:
if (semanticModel.GetDeclaredSymbol(typeDecl) is not INamedTypeSymbol typeSymbol || typeSymbol.IsAbstract)

// After: 
if (semanticModel.GetDeclaredSymbol(typeDecl) is not INamedTypeSymbol typeSymbol || typeSymbol.IsAbstract || typeSymbol.IsStatic)

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.

Copilot AI and others added 3 commits September 10, 2025 10:10
… bug

Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] 0.57.63 broken source generator Fix PropertyInjectionSourceGenerator processing static extension method classes Sep 10, 2025
@Copilot Copilot AI requested a review from thomhurst September 10, 2025 10:17
Copilot finished work on behalf of thomhurst September 10, 2025 10:17
@thomhurst thomhurst closed this Sep 10, 2025
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.

0.57.63 broken source generator

2 participants