Collection Initializer cannot handle Extensions akin to IEnumerable<T>.Add(IEnumerable<T>)
( IDE0028
vs CS0029
)
#72460
Labels
IEnumerable<T>.Add(IEnumerable<T>)
( IDE0028
vs CS0029
)
#72460
Version Used:
Visual Studio: Version 17.9.2
dotnet: 6.0.419
Steps to Reproduce:
invoke CodeFix
get compiler error
A minimal repro, with source-code provided, is ideal. Using sharplab is preferred for compiler/language issues whenever possible.
Diagnostic Id:
IDE0028
Collection initialization can be simplifiedCS0029
Cannot implicitly convert type 'System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, int>>' to 'System.Collections.Generic.KeyValuePair<string, int>' ClassLibrary2 D:\repos\WinFormsApp1\ClassLibrary2\Class1.csExpected Behavior:
something like
Actual Behavior:
Notes:
we've experienced the same Problem with Lists/Collections (ie Generics with Arity=1), however I'm unable to get a working minimal example:
(in this case
ExecuteSync()
returns anICollection<string?>
, but we know it's exactly one element so capacity=2)corrected (and working):
The text was updated successfully, but these errors were encountered: