maraaaaaaaa
maraaaaaaaa

Reputation: 8163

Is IAsyncEnumerable supported in C# 8.0?

Its really hard to find any information on IAsyncEnumerable, other than a few mentions in the 'What's New c# 8.0' articles. Trying to use it in Visual Studio 2019 with netstandard 2.0 and C# 8 enabled, it does recognize the class but i get a ton of errors on build:

enter image description here

Upvotes: 6

Views: 3740

Answers (4)

damjik
damjik

Reputation: 61

The answer of Vlad is the right one.

  1. Add LangVersion 8.0 to the desired Projects PropertGroup
  2. Add the Microsoft.Bcl.AsyncInterfaces as PackageReference

For example: MyDummyLib.csproj

<PropertyGroup>
    <TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
    <LangVersion>8.0</LangVersion>
    <AssemblyName>MyDummyLib</AssemblyName>
    <RootNamespace>MyDummyLib</RootNamespace>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
    <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.1" />
</ItemGroup>

Upvotes: 6

VladOhotnikov
VladOhotnikov

Reputation: 1188

For .NET Standard 2.0 you should install Microsoft.Bcl.AsyncInterfaces

https://www.nuget.org/packages/Microsoft.Bcl.AsyncInterfaces/

Upvotes: 5

TheGeneral
TheGeneral

Reputation: 81493

C# 8 supports these features. However, this wont work with .Net standard 2.0

IAsyncEnumerable Interface

Applies to

.NET Core 3.0 Preview 3

.NET Standard 2.1 Preview

You will have to get either one of the previews.

You can find more information on .Net Core 3 Preview here

Upvotes: 7

Casey Rojas
Casey Rojas

Reputation: 39

Looks like you need to target .NET Standard 2.1 but it’s still only in preview.

https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=netstandard-2.1

Upvotes: 0

Related Questions