Skip to content

New warning CS9220 for Razor code using string.Join #73643

Closed
@eerhardt

Description

@eerhardt

See dotnet/aspnetcore#55780 (comment) for the original conversation

Version Used: .NET SDK 9.0.100-preview.5.24262.2

Steps to Reproduce:

  1. In a .cshtml MVC file write the following code:
<cache>Products: @string.Join(", ", ProductsService.GetProductNames(ViewBag.Category)) (@ViewBag.CorrelationId)</cache> 

Where the ProductsService.GetProductNames method looks like:

public IEnumerable<string> GetProductNames(string category) 
{
    return new string[] { "one", "two" };
}

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

Diagnostic Id: CS9220

Expected Behavior:

Before .NET 9, the above code compiled successfully without warnings.

Actual Behavior:

Using .NET 9, the code now produces a new warning:

src/Mvc/test/WebSites/HtmlGenerationWebSite/Views/Catalog_CacheTagHelper/ListCategories.cshtml(4,19): error CS9220: (NETCORE_ENGINEERING_TELEMETRY=Build) One or more overloads of method 'Join' having non-array params collection parameter might be applicable only in expanded form which is not supported during dynamic dispatch.

This was discovered when taking a new dotnet/runtime version with dotnet/runtime#101499 which added the params keyword to parameters of string.Join.

cc @AlekseyTs @jaredpar @jozkee @javiercn

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions