Ambiguous overload resolution affecting StringValues implicit operators
In .NET 9, a breaking change in the params Span<T>
lang feature creates ambiguity with the implicit operators of StringValues. This change results in the compiler throwing error CS0121
when it encounters ambiguous method calls.
Previous behavior
The APIs mentioned in the Affected APIs section previously had no overloads ambiguous with the implicit operators of StringValues. As a result, the compiler would resolve the overloads without any issues.
New behavior
The compiler throws error CS0121
when encountering these ambiguous overloads, resulting in the following error:
CS0121: The call is ambiguous between the following methods or properties: 'Program.Join(string, params string[])' and 'Program.Join(string, params ReadOnlySpan<string>)'
Version introduced
.NET 9
Type of breaking change
This change is a source compatibility change.
Reason for change
StringValues has implicit operators for string
and string[]
that cause conflicts with the params Span<T>
lang feature.
Recommended action
Explicitly specify the method you intend to call by casting the arguments to the appropriate type or apply named parameters.
Affected APIs
- System.String.Concat(ReadOnlySpan<String>)
- System.String.Join(Char, ReadOnlySpan<String>)
- System.String.Join(String, ReadOnlySpan<String>)
- System.IO.Path.Combine(ReadOnlySpan<String>)
- System.IO.Path.Join(ReadOnlySpan<String>)
- System.Text.StringBuilder.AppendJoin(String, ReadOnlySpan<String>)
- System.Text.StringBuilder.AppendJoin(Char, ReadOnlySpan<Object>)