Skip to content

required and GenerateReferenceAssemblySource #71559

@ManickaP

Description

@ManickaP

When using the new required keyword, GenerateReferenceAssemblySource generates code like this:

[System.Runtime.CompilerServices.RequiredMemberAttribute]
public sealed partial class QuicClientConnectionOptions : System.Net.Quic.QuicConnectionOptions
{
    [System.ObsoleteAttribute("Constructors of types with required members are not supported in this version of your compiler.", true)]
    [System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute("RequiredMembers")]
    public QuicClientConnectionOptions() { }
    [System.Runtime.CompilerServices.RequiredMemberAttribute]
    public System.Net.Security.SslClientAuthenticationOptions ClientAuthenticationOptions { get { throw null; } set { } }
    public System.Net.IPEndPoint? LocalEndPoint { get { throw null; } set { } }
    [System.Runtime.CompilerServices.RequiredMemberAttribute]
    public System.Net.EndPoint RemoteEndPoint { get { throw null; } set { } }
}

And then compiler complains that required keyword should be used instead:

System.Net.Quic.cs(10,6): error CS9033: Do not use 'System.Runtime.CompilerServices.RequiredMemberAttribute'. Use the 'required' keyword on required fields and properties instead.

I don't know which way is the correct way. @ViktorHofer @333fred

Follow up issue is that if I manually remove the attributes and add required keyword, the GeneratePlatformNotSupportedAssemblyMessage generator generates another code that cannot be compiled. See the missing get and set:

public sealed partial class QuicClientConnectionOptions : System.Net.Quic.QuicConnectionOptions
{
    public QuicClientConnectionOptions() { throw new System.PlatformNotSupportedException(System.SR.SystemNetQuic_PlatformNotSupported);  }
    public required System.Net.Security.SslClientAuthenticationOptions ClientAuthenticationOptions { throw new System.PlatformNotSupportedException(System.SR.SystemNetQuic_PlatformNotSupported);  }
    public System.Net.IPEndPoint? LocalEndPoint { get { throw new System.PlatformNotSupportedException(System.SR.SystemNetQuic_PlatformNotSupported);  } set { throw new System.PlatformNotSupportedException(System.SR.SystemNetQuic_PlatformNotSupported);  } }
    public required System.Net.EndPoint RemoteEndPoint { throw new System.PlatformNotSupportedException(System.SR.SystemNetQuic_PlatformNotSupported);  }
}

Does anyone know where the GeneratePlatformNotSupportedAssemblyMessage lives and whom to contact?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions