Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msbuild throws CS9215, but dotnet build doesn't #11449

Closed
virzak opened this issue Feb 13, 2024 · 1 comment
Closed

msbuild throws CS9215, but dotnet build doesn't #11449

virzak opened this issue Feb 13, 2024 · 1 comment

Comments

@virzak
Copy link

virzak commented Feb 13, 2024

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

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];
}

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.

image

@KalleOlaviNiemitalo
Copy link

The collection expression conversion rules regarding iteration type were changed in dotnet/csharplang#7783. That's why the compiler no longer allows the conversion.

@MiYanni MiYanni transferred this issue from dotnet/sdk Feb 14, 2025
@MiYanni MiYanni removed their assignment Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants