Skip to content

CA2026 autofix generating non-compiling code #57198

Open

Description

@areevesat

Describe the bug

CA2026 raises a warning when using JsonDocument.Parse(...).RootElement and suggests using JsonElement.Parse(...) instead. The autofix for this generates non-compiling code.

Steps to reproduce

Write code that uses the incorrect pattern.

var root = JsonDocument.Parse(response).RootElement;

Run the auto-fix. The below is the result, which does not compile:

var root = JsonElement.Parse(response, JsonDocument.Parse(response));

Expected behavior

The autofix should not place in an invented value for the JsonDocumentOptions optional value. It should leave that blank, or conceivably include an options value if one is already present in the file.

Below is what I would expect to see from the autofix.

var root = JsonElement.Parse(response);

Actual behavior

The below is the result, which does not compile:

var root = JsonElement.Parse(response, JsonDocument.Parse(response));

Is this a regression?

No response

Are there any workarounds?

No response

dotnet --info output

.NET SDK:
 Version:           11.0.100
 Commit:            297acf930f
 Workload version:  11.0.100-manifests.08e30c08
 MSBuild version:   18.12.2-1.26529.118+297acf930

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26200
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\11.0.100

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
  Version:      11.0.0
  Architecture: x64
  Commit:       297acf930f

.NET SDKs installed:
  10.0.201 [C:\Program Files\dotnet\sdk]
  10.0.300 [C:\Program Files\dotnet\sdk]
  10.0.401 [C:\Program Files\dotnet\sdk]
  11.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 11.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 11.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 11.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  DOTNET_CLI_UI_LANGUAGE                   [en-US]

global.json file:
  D:\Github\mototrax-backend\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

IDE version

Visual Studio 2026, version 18.10.3

Other details

No response

Activity

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

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    ➡️ Summary: The CA2026 code fix rewrites JsonDocument.Parse(x).RootElement into non-compiling JsonElement.Parse(x, JsonDocument.Parse(x)). Fix the code fixer to omit the invented options argument.

    Generated by 🏷️ Issue Triage for #57198 · copilot · auto (Claude Sonnet 5.5) · ~16 AIC · ⌖ ~2 AIC · ⊞ 15.5K · ◷

  6. github-actions commented on Nov 19, 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 (Claude Sonnet 5.5) · ~15 AIC · ⌖ ~25 AIC · ⊞ 13.6K · ◷

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