Skip to content

Roslyn JSON detection marks strings as JSON even if StringSyntaxAttribute says it's not. #74020

@maartenvansambeek

Description

@maartenvansambeek

Version Used:
4.10.0

Steps to Reproduce:

  1. Create a program that has a field marked as something that is not json by using a [StringSyntax] attribute,
  2. Look at the highlighted text in the IDE.

Example program:

using System.Diagnostics.CodeAnalysis;

class Program
{
    [StringSyntax("notjson")]
    private string field;
    void Goo()
    {
        // The JSON constant below is highlighted as json:
        this.field = @"[{ 'goo': 0}]";
    }
}

A minimal repro, with source-code provided, is ideal. Using sharplab is preferred for compiler/language issues whenever possible.

Diagnostic Id:

If this is a report about a bug in an analyzer, please include the diagnostic ID and message if possible (e.g. "IDE0030: Use coalesce expression").

Expected Behavior:

The constant string is not highlighted as JSON.

Actual Behavior:

The constant string is highlighted as JSON.

A PR was created for this issue: #74019

Metadata

Metadata

Labels

Area-IDEuntriagedIssues and PRs which have not yet been triaged by a lead

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions