Skip to content

CA1517 false positive when indexing and writing directly to a member data[0].X = 1 #57061

Open

Description

@Miizukii

Describe the bug

Version Used: .NET SDK 11.0.100

Steps to reproduce

using System.Numerics;

Test.SetX([default]);

public static class Test
{
    internal static void SetX(Span<Vector2> data)
    {
        for (var i = 0; i < data.Length; i++)
            data[i].X = 1;
    }
}

Expected behavior

No diagnostic.

Actual behavior

CA1517 : Parameter 'data' can be declared as 'ReadOnlySpan' instead of as 'Span

Other details

also the page does not exist:
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1517

Activity

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

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    Similar issues: #56292 (potentially related)

    ➡️ Summary: CA1517 is falsely reported for Span(Vector2) when a struct member is written via data[i].X = 1. Follow up by treating writes through element member access as mutation, like the ref-foreach fix.

    Generated by 🏷️ Issue Triage for #57061 · copilot · auto · ~13 AIC · ⌖ ~1 AIC · ⊞ 14.6K · ◷

  6. github-actions commented on Nov 12, 2026

    @github-actions
    Contributor

    🍪 Issue Monster selected this for Copilot

    I have identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster Orchestrator · copilot · auto · ~13 AIC · ⌖ ~15 AIC · ⊞ 13.2K · ◷

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions