Back to Aspnetcore

RDG005: Invalid abstract type

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

latest1.6 KB
Original Source

RDG005: Invalid abstract type

<!-- UPDATE 9.0 Activate after release and INCLUDE is updated [!INCLUDE[](~/includes/not-latest-version.md)] -->
Value
Rule IDRDG005
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 that is an abstract type.

Rule description

The implementation of surrogate binding via the [AsParameters] attribute in Minimal APIs only supports types with concrete implementations. Using a parameter with an abstract type as in the following sample produces the diagnostic.

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg5/Program.cs" id="snippet_1" highlight="13, 17-21"::: Id, string Task);

How to fix violations

Use a concrete type for the surrogate:

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg5/Program.cs" id="snippet_1f" highlight="14,18-22":::

When to suppress warnings

This warning should not be suppressed. Suppressing the warning will lead to a runtime exception assocaited with the same warning.