roslyn: C# 11 required properties do not compile on dotnet 6

[Update(jcouv):] The ask is that required properties not be recommended by the IDE on .NET 6 or lower.

Describe the bug

When I want to use required properties in a project targeting net6.0 with LangVersion set to latest I face some compile errors.

To Reproduce

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <LangVersion>latest</LangVersion>
    </PropertyGroup>

</Project>

namespace Csharp11OnDotnet6;

public class Person
{
    public required string Name { get; init; }
}

2.dotnet build

Exceptions (if any)

error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.RequiredMemberAttribute..ctor'
error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.CompilerFeatureRequi
redAttribute..ctor'

Expected Behavior: build successful

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@jcouv

1.use The "required members" feature is part of C# 11 and is only supported on .NET 7 and up instead of Missing compiler required member 'System.Runtime.CompilerServices.RequiredMemberAttribute..ctor' for the error

2.In .net 6 projects, IntelliSense should not recommend “required members”