Skip to content

IDE0028 warns to use an unsupported preview feature, collection expression arguments #82586

@anthonymastreanvae

Description

@anthonymastreanvae

Version Used: .NET 10.0.103

I have LangVersion set to latest, but this analyzer is showing a warning and recommending a fix that breaks the build. Not sure why the initial warning doesn't fail the build, as I also have TreatWarningsAsErrors set to true on CI.

Dictionary<string, object> dict1 = [];
Dictionary<string, object> dict2 = new(dict1); // ⚠️ IDE0028: Collection initialization can be simplified

Diagnostic Id: IDE0028

Use collection initializers or expressions (IDE0028)

Expected Behavior:

I did not expect an analyzer to recommend unsupported preview features! 😁

Collection expression arguments

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/collection-expressions#collection-expression-arguments

Actual Behavior:

Accept the codefix:

Dictionary<string, object> dict1 = [];
Dictionary<string, object> dict2 = [with(dict1)]; // ❌ CS8652: The feature 'collection expression arguments' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions