Back to Aspnetcore

RDG004: Unable to resolve anonymous type

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

latest1.4 KB
Original Source

RDG004: Unable to resolve anonymous type

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

Rule description

The Request Delegate Generator runs at compile-time and needs to be able to statically analyze route handlers in an app. Anonymous types are generated with a type name only known to the complier and aren't statically analyzable. The following endpoint produces the diagnostic.

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg4/Program.cs" id="snippet_1" highlight="13":::

How to fix violations

Declare the route handler with a concrete type as the return type.

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg4/Program.cs" id="snippet_1f" highlight="13":::

When to suppress warnings

This warning can be safely suppressed. When suppressed, the framework falls back to generating the request delegate at runtime.