Skip to content

Fix source generator crash when parameter type uses verbatim @ keyword prefix#208

Merged
PhenX merged 2 commits into
masterfrom
copilot/fix-source-generator-error
May 16, 2026
Merged

Fix source generator crash when parameter type uses verbatim @ keyword prefix#208
PhenX merged 2 commits into
masterfrom
copilot/fix-source-generator-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

Roslyn's FullyQualifiedFormat includes the @ verbatim escape prefix for types whose names are reserved C# keywords (e.g. global::ProjectName.Storage.@event). This @ ended up in the generated hint name, which Roslyn rejects as invalid — causing the generator to silently fail and EF Core to throw at runtime.

Root cause

AppendSanitizedTypeName stripped global:: but left @ untouched. Since @ has no CLR-level meaning (the runtime type name is just event, not @event), it must be skipped entirely — not replaced — so the generator and the runtime resolver produce identical class names.

Changes

  • ProjectionExpressionClassNameGenerator.AppendSanitizedTypeName — skip @ characters in the same pass that skips global::, ensuring the generated class name (and hint/file name) never contains @
  • ProjectionExpressionClassNameGeneratorTests — three new [InlineData] cases covering global::Foo.Storage.@event, bare @event, and global::Foo.@delegate
  • ExtensionMethodTests — new snapshot test for an extension method whose this parameter type is @event; verified output uses Foo_EventExtensions_GetId_P0_Foo_event (no @)

Example

// Previously caused CS8785 generator failure + runtime InvalidOperationException
public static class EventExtensions
{
    [Projectable]
    public static int GetId(this @event e) => e.Id;
}

Copilot AI linked an issue May 16, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix source generator failure with entities marked with '@' Fix source generator crash when parameter type uses verbatim @ keyword prefix May 16, 2026
Copilot AI requested a review from PhenX May 16, 2026 06:57
Copilot finished work on behalf of PhenX May 16, 2026 06:57
@PhenX PhenX marked this pull request as ready for review May 16, 2026 07:04
@PhenX PhenX merged commit 68a4599 into master May 16, 2026
4 checks passed
@PhenX PhenX deleted the copilot/fix-source-generator-error branch May 16, 2026 07:05
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.

Source generator fails with entities marked with '@'

2 participants