Back to Aspnetcore

RDG008: Multiple public constructors

aspnetcore/fundamentals/aot/request-delegate-generator/diagnostics/rdg008.md

latest1.4 KB
Original Source

RDG008: Multiple public constructors

<!-- UPDATE 9.0 Activate after release and INCLUDE is updated [!INCLUDE[](~/includes/not-latest-version.md)] -->
Value
Rule IDRDG008
Fix is breaking or non-breakingNon-breaking

Cause

This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler with a parameter annotated with the [AsParameters] attribute with multiple public constructors.

Rule description

Types that are used for surrogate binding via the AsParameters attribute must contain a single public constructor. The TodoRequest type produces this diagnostic because there are multiple public constructors.

<!--Sample code requires removing https from properties/launchsettings.json -->

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg8/Program.cs" id="snippet_1" highlight="17,32-43":::

How to fix violations

Provide a single public constructor.

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg8/Program.cs" id="snippet_1f" highlight="17,45":::

When to suppress warnings

This warning can be safely suppressed.