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

Copilot AI commented May 16, 2026

Copy link
Copy Markdown
Contributor

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
github-merge-queue Bot pushed a commit to DFE-Digital/teaching-record-system that referenced this pull request Jul 22, 2026
Updated
[EntityFrameworkCore.Projectables](https://github.com/EFNext/EntityFrameworkCore.Projectables)
from 6.0.4 to 6.0.6.

<details>
<summary>Release notes</summary>

_Sourced from [EntityFrameworkCore.Projectables's
releases](https://github.com/EFNext/EntityFrameworkCore.Projectables/releases)._

## 6.0.6

## What's Changed
* Preserve nullable typing for ignored null-conditional access in
coalesce expressions by @​PhenX with @​Copilot in
EFNext/EntityFrameworkCore.Projectables#212
* Fix duplicate joins when materializing writable projectables with
includes by @​PhenX in
EFNext/EntityFrameworkCore.Projectables#218


**Full Changelog**:
EFNext/EntityFrameworkCore.Projectables@v6.0.5...v6.0.6

## 6.0.5

## What's Changed
* Fix source generator crash when parameter type uses verbatim @ keyword
prefix by @​Copilot in
EFNext/EntityFrameworkCore.Projectables#208


**Full Changelog**:
EFNext/EntityFrameworkCore.Projectables@v6.0.4...v6.0.5

Commits viewable in [compare
view](EFNext/EntityFrameworkCore.Projectables@v6.0.4...v6.0.6).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=EntityFrameworkCore.Projectables&package-manager=nuget&previous-version=6.0.4&new-version=6.0.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: James Gunn <james@gunn.io>
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