Is IAsyncEnumerable supported in C# 8.0?
Asked Answered
I

4

6

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

Intersperse answered 24/4, 2019 at 2:58 Comment(2)
are there images of error messages?Johannajohannah
C# 8 supports those things, but doesn't define them. You need to target a release of .NET that does, which, at the moment, is only the preview release of .NET Core 3.0.Dingdong
H
7

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

Hent answered 24/4, 2019 at 3:2 Comment(2)
So just a heads up for anyone planning on trying this, unfortunately it wont work if you use Net Core 3.0 along with EntityframeworkCore, because of the following error: Error CS0433 The type 'IAsyncEnumerable<T>' exists in both 'System.Interactive.Async, Version=3.2.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' and 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'Intersperse
Just ran into the above comment myself. Was trying to try out IAsyncEnumerable with providing a InMemory database for data but nope! Dreams crushed.Pellagra
L
6

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>
Liberty answered 9/11, 2020 at 8:56 Comment(0)
I
5

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

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

Inflationism answered 30/9, 2020 at 7:1 Comment(2)
Please don't just post some tool or library as an answer. At least demonstrate how it solves the problem in the answer itself.Gerhard
Since the problem is about missing member IAsyncEnumerable .NET Standard 2.0 - this packet publishied by Microsoft for compatibility in .NET Standard 2.0. You don't need do anything acept install it.Inflationism
Q
0

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

Quadrennial answered 24/4, 2019 at 3:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.