Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IAsyncEnumerable<> broken in VS 2019 preview 2 (Core 3.0 preview 1)

After installing VS 2019 preview 2 i get a great number of errors. Error demo code:

public class Class1 {
    public static async IAsyncEnumerable<int> Get()
    {
        for( int i = 0; i < 10; i++ ) {
            await Task.Delay( 100 );
            yield return i;
        }
    }
}

and nothig more (a new dll project)!
With preview 1 was ok.

The project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>
</Project>

The error message is: Error CS0656 Missing compiler required member 'System.Collections.Generic.IAsyncEnumerable`1.GetAsyncEnumerator'

Object Browser shows the member in Collections.Generic.

Any ideas? Waiting for Core 3.0 preview 2?

Something like in IAsyncEnumerable not working in C# 8.0 preview ?

Another problem with VS 2019 P2 (another project): Nullabilty warnings though NullableReferenceTypes line is there (in vs 19, preview 1 was ok):

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <LangVersion>8.0</LangVersion>
    **<NullableReferenceTypes>true</NullableReferenceTypes>**

The warning:
Warning CS8632 The annotation for nullable reference types should only be used in code within a '#nullable' context.
Is project setting not enough? not global any more?

like image 718
me-on-stov Avatar asked Jan 25 '19 11:01

me-on-stov


People also ask

What is .NET 6 vs .NET Core?

NET 6, though, is ASP.NET Core 6, a major upgrade of Microsoft's open source framework for building modern web applications. ASP.NET Core 6 is built on top of the . NET Core runtime and allows you to build and run applications on Windows, Linux, and macOS. ASP.NET Core 6 combines the features of Web API and MVC.

What is .NET core3?

NET unification is the support for Windows desktop applications. With this addition, . NET Core 3.0 allows you to run new and existing Windows desktop applications using the UI framework of your choice. In fact, the new release brings Windows Forms (WinForms) and Windows Presentation Foundation (WPF) to . NET Core.

What changed in .NET 6?

Better performance: . NET 6 is the fastest full stack web framework, which lowers compute costs if you're running in the cloud. Ultimate productivity: . NET 6 and Visual Studio 2022 provide hot reload, new git tooling, intelligent code editing, robust diagnostics and testing tools, and better team collaboration.


2 Answers

Problem 1

Missing compiler required member 'System.Collections.Generic.IAsyncEnumerable`1.GetAsyncEnumerator'

Solution

Install .NET Core v3.0.100-preview-010177

https://github.com/dotnet/core-sdk#installers-and-binaries

Explanation

There was a breaking change to IAsyncEnumerable from .NET Core 3 Preview 1 to .NET Core Preview 2

Async streams

We changed the shape of the IAsyncEnumerable interface the compiler expects! This brings the compiler out of sync with the interface provided in .NET Core 3.0 Preview 1, which can cause you some amount of trouble. However, .NET Core 3.0 Preview 2 is due out shortly, and that brings the interfaces back in sync.

Source: https://blogs.msdn.microsoft.com/dotnet/2019/01/24/do-more-with-patterns-in-c-8-0/

Problem 2

The annotation for nullable reference types should only be used in code within a '#nullable' context

Solution

Change<NullableReferenceTypes>true</NullableReferenceTypes>

to

<NullableContextOptions>enable</NullableContextOptions>

Explanation

This is a breaking change from VS2019 Preview 1 to VS2019 Preview 2.

Nullable reference types

We’ve added more options to control nullable warnings both in source (through #nullable and #pragma warning directives) and at the project level. We also changed the project file opt-in to enable.

Source: https://blogs.msdn.microsoft.com/dotnet/2019/01/24/do-more-with-patterns-in-c-8-0/

like image 109
Brandon Minnick Avatar answered Jan 04 '23 11:01

Brandon Minnick


Replacing

<NullableReferenceTypes>true</NullableReferenceTypes>

With

<NullableContextOptions>enable</NullableContextOptions>

Fixed my issues with nullable reference types.

EDIT:

It may be worth having both options in the .csproj file as the dotnet Docker images has not yet been updated and will fail as it does not recognize the new nullable reference type tag

like image 30
JonasMH Avatar answered Jan 04 '23 11:01

JonasMH