Skip to content

Polyfill IAsyncEnumerable from Microsoft.Bcl.AsyncInterfaces does not work in net8.0 without reference to Microsoft.Bcl.AsyncInterfaces #115124

Open
@m-redding

Description

@m-redding

Description

This might be by-design because of the nature of polyfilling, but I want to understand if that's the case, and if there are any workarounds.

This is a problem in the azure-sdk-for-net repository, but I created a standalone minimal repo that demonstrates the exact issue I'm seeing because it's really difficult to explain: DependencyRepro

  • BaseLibrary (represents Azure.Core)
    • BaseLibrary.csproj multi-targets netstandard2.0 and net8.0, netstandard2.0 target has a dependency on Microsoft.Bcl.AsyncInterfaces while net8.0 does not
    • AsyncPageable implements IAsyncEnumerable
  • SdkLibrary
    • SdkLibrary.csproj ONLY targets netstandard2.0 and has a dependency on BaseLibrary, depends on BaseLibrary to transitively get dependency on Microsoft.Bcl.AsyncInterfaces
    • CollectionClass inherits from IAsyncEnumerable and uses AsyncPageable
  • CustomerApp
    • CustomerApp.csproj net9.0 app, depends on SdkLibrary, doesn't get Microsoft.Bcl.AsyncInterfaces transitively because it uses the net8.0 target of BaseLibrary
    • Program.cs cannot use await foreach on an instance of CollectionClass unless the app adds a direct dependency on Microsoft.Bcl.AsyncInterfaces

Reproduction Steps

See repository above

Expected behavior

It would be ideal if the customer app could build without needing a dependency on Microsoft.Bcl.AsyncInterfaces

Actual behavior

Build fails with error stating that the app needs a reference on Microsoft.Bcl.AsyncInterfaces

Regression?

No response

Known Workarounds

  • Adding a net8.0 target to SdkLibrary
  • Keep the reference to Microsoft.Bcl.AsyncInterfaces in the net8.0 target in BaseLibrary - this is the current solution
  • Adding a direct reference to Microsoft.Bcl.AsyncInterfaces in the customer app (non-solution in the real scenario as this could be breaking)

Configuration

This is not specific to any OS / .NET SDK version

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-MetauntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions