Skip to content

C# 11 required properties do not compile on dotnet 6 #68478

@Varorbc

Description

@Varorbc

[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

Metadata

Metadata

Assignees

Labels

Area-IDEFeature - Required MembersRequired properties and fieldsuntriagedIssues and PRs which have not yet been triaged by a lead

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions