Skip to content

CA2264 code fix produces uncompilable code for an expression-bodied member #56775

Open

Description

@Hanif6731

Describe the bug

The CA2264 code fix ("Calling 'ArgumentNullException.ThrowIfNull' and passing a non-nullable value is a no-op") removes the
call. When the call is the whole body of an expression-bodied member, the fix removes the body as well and leaves a
member declaration with no body, which does not compile (CS0501).

To Reproduce

SDK 10.0.402, a new class library targeting net10.0:

namespace Repro;

public sealed class Sample
{
    public void M(int value) => ArgumentNullException.ThrowIfNull(value);
}

.editorconfig:

root = true
[*.cs]
dotnet_diagnostic.CA2264.severity = warning

Run:

dotnet format analyzers --diagnostics CA2264 --severity warn
dotnet build

Expected behavior

The member still compiles after the fix, for example:

public void M(int value) { }

Actual behavior

public void M(int value) ;
error CS0501: 'Sample.M(int)' must declare a body because it is not marked abstract, extern, or partial

Additional context

  • The same call in an expression-bodied lambda (value => ArgumentNullException.ThrowIfNull(value)) or local function
    is reported but left unchanged by the fix, so only expression-bodied members are affected.
  • The fix lives in DoNotPassNonNullableValueToArgumentNullExceptionThrowIfNull.Fixer.cs.
    Removing the invocation statement is right in a block body; for an arrow expression clause it needs to become an
    empty block (or the fix should not be offered there, as for lambdas).
  • Found while running dotnet format across a solution with CA2264 enabled at warning level.

Activity

  1. added
    untriaged
    on Oct 24, 2026
  2. locked and limited conversation to collaborators on Oct 24, 2026
  3. unlocked this conversation on Oct 24, 2026
  4. added
    cookie
    and removed
    untriaged
    on Oct 24, 2026
  5. github-actions commented on Oct 24, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    ➡️ Summary: The CA2264 code fix removes an expression-bodied member body, leaving uncompilable code (CS0501). Fix by replacing the arrow body with an empty block or not offering the fix.

    Generated by 🏷️ Issue Triage for #56775 · copilot · auto · 20.3 AIC · ⌖ 0.731 AIC · ⊞ 14.4K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions