JoshClose / CsvHelper

Library to help reading and writing CSV files
http://joshclose.github.io/CsvHelper/
Other
4.63k stars 1.05k forks source link

List<T>.ToAsyncEnumerable not accessible anymore after upgrade to CSVHelper 31.0.2 (.NET 8) #2239

Closed moosetraveller closed 4 months ago

moosetraveller commented 4 months ago

Describe the bug Upgrading from CSVHelper 31.0.0 to 31.0.2 breaks my build. For example, List<T>.ToAsyncEnumerable is not accessible anymore.

error CS1061: 'List<T>' does not contain a definition for 'ToAsyncEnumerable' and no accessible extension method 
'ToAsyncEnumerable' accepting a first argument of type 'List<T>' could be found (are you missing a using
directive or an assembly reference?)

To Reproduce Upgrading from CSVHelper 31.0.0 to 31.0.2. Unfortunately, I don't have a minimal working example to share. I am using VSCode as an IDE but I don't think that has a relevance and I am using .NET 8.

Expected behavior List<T>.ToAsyncEnumerable should be accessible.

moosetraveller commented 4 months ago

This combination works:

<ItemGroup>
  <PackageReference Include="AspNetCore.Proxy" Version="4.4.0" />
  <PackageReference Include="CSVHelper" Version="31.0.0" />
  <PackageReference Include="HtmlSanitizer" Version="8.0.843" /> <!-- Ganss.XSS -->
  <PackageReference Include="MailKit" Version="4.4.0" />
  <PackageReference Include="Markdig.Signed" Version="0.35.0" />
  <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
  <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
  <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
  </PackageReference>
  <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.2" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="8.0.2" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
  </PackageReference>
  <PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
  <PackageReference Include="MimeKit" Version="4.4.0" />
  <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
  <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="8.0.2" />
  <PackageReference Include="Quartz" Version="3.8.1" />
  <PackageReference Include="Quartz.AspNetCore" Version="3.8.1" />
  <PackageReference Include="Quartz.Extensions.DependencyInjection" Version="3.8.1" />
  <PackageReference Include="Quartz.Extensions.Hosting" Version="3.8.1" />
  <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

But not when using:

<PackageReference Include="CSVHelper" Version="31.0.2" />
moosetraveller commented 4 months ago

I see that System.Linq.Async was removed with commit 2efe3a4. However, it does not make sense that this breaks my application.

If I add an unit test:

using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace CsvHelper.Tests.Issues
{
    public class Issue2239
    {
        [Fact]
        public async void Issue2239Test()
        {
            List<string> values = ["a", "b", "c", "d", "e"];

            var updatedValues = await values.ToAsyncEnumerable() 
                .Where(value => value != "e")
                .ToListAsync();
        }
    }
}

And then remove <PackageReference Include="System.Linq.Async" Version="6.0.1" /> in CsvHelper.Tests.csproj, I get the same error.

It does not make sense to me. I have Microsoft.EntityFrameworkCore as a dependency added and also use using Microsoft.EntityFrameworkCore;.

My application breaks when upgrading from 31.0.0 to 31.0.2 (without any other changes).

JoshClose commented 4 months ago

There apparently is a conflict between System.Linq.Async and EntityFramework. System.Linq.Async was used for a single method call, so I removed it and change the code slightly. I'll have to look into why that's not available for you now.

moosetraveller commented 4 months ago

I have solved it by adding <PackageReference Include="System.Linq.Async" Version="6.0.1" /> to my project.

Nothing is wrong with the CSVHelper. I was using ToAsyncEnumerable() not realizing that it was provided from a third-party library through CSVHelper. I am very sorry for having added work to your plate.

JoshClose commented 4 months ago

Ha! No worries.