5

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?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
me-on-stov
  • 69
  • 1
  • 5
  • 3
    Yes, this is broken for the moment and it will be fixed. See "changes since preview 1" in [Mads' blog](https://blogs.msdn.microsoft.com/dotnet/2019/01/24/do-more-with-patterns-in-c-8-0/), which mentions both issues. – Jeroen Mostert Jan 25 '19 at 11:46
  • 1
    Now, who voted to close *this* question? It's certainly reproducible and officially acknowledged – Panagiotis Kanavos Jan 28 '19 at 08:24
  • This is definitely a "something like this case" but you can't just add the missing classes this time. `IAsyncEnumerable` exists but the methods are different. You can't fake it with an extension method and any techniquest that would inject the missing method aren't worth it. You'll have to use a daily build or wait for Core 3.0 Preview 2. OTOH, given how volatile those previews are, might as well use the dailies – Panagiotis Kanavos Jan 28 '19 at 08:27

3 Answers3

8

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/

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
3

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

JonasMH
  • 1,145
  • 11
  • 21
0

In Visual Studio 16.2 the property name changed to Nullable which is simpler and aligns with the command line argument.

<PropertyGroup>
  <LangVersion>8.0</LangVersion>
  <Nullable>enable</Nullable>
</PropertyGroup>
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742