Using MSBuild version 17.10.0-preview-24081-01+97651a25d
Getting an MSBuild error:
error CS9215: Collection expression type must have an applicable instance or extension method 'Add' that can be called with an argument of iteration type 'object'. The best overloaded method is 'MyClass.Add(int)'
using System;
using System.Collections;
using System.Collections.Generic;
Console.WriteLine("🌄");
class MyClass<T> : IEnumerable
{
readonly List<object> list = [];
public void Add(T p)
{
list.Add(p);
}
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
}
class MyClass2
{
MyClass<int> myClass = [4];
}
The collection expression conversion rules regarding iteration type were changed in https://github.com/dotnet/csharplang/pull/7783. That's why the compiler no longer allows the conversion.
Description
Using MSBuild version 17.10.0-preview-24081-01+97651a25d
Getting an MSBuild error:
error CS9215: Collection expression type must have an applicable instance or extension method 'Add' that can be called with an argument of iteration type 'object'. The best overloaded method is 'MyClass.Add(int)'
Reproduction Steps
Here is a sharplab link
Expected behavior
Compiles just fine using
dotnet build
Actual behavior
Although this is still .NET 8, Visual Studio
Regression?
Yes. Used to work with previous versions.
Known Workarounds
No response
Configuration
No response
Other information
This happens when using @davidwengier 's Xunit.SerializedTheoryData library.