Fix source generator crash when parameter type uses verbatim @ keyword prefix#208
Merged
Conversation
…ameter type names Agent-Logs-Url: https://github.com/EFNext/EntityFrameworkCore.Projectables/sessions/c8748592-1460-4fb8-bd4d-b8eb20d15ce3 Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
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
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Roslyn's
FullyQualifiedFormatincludes 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
AppendSanitizedTypeNamestrippedglobal::but left@untouched. Since@has no CLR-level meaning (the runtime type name is justevent, 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 skipsglobal::, ensuring the generated class name (and hint/file name) never contains@ProjectionExpressionClassNameGeneratorTests— three new[InlineData]cases coveringglobal::Foo.Storage.@event, bare@event, andglobal::Foo.@delegateExtensionMethodTests— new snapshot test for an extension method whosethisparameter type is@event; verified output usesFoo_EventExtensions_GetId_P0_Foo_event(no@)Example