Back to Aspnetcore

RDG013: Invalid source attributes

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

latest1.6 KB
Original Source

RDG013: Invalid source attributes

<!-- UPDATE 9.0 Activate after release and INCLUDE is updated [!INCLUDE[](~/includes/not-latest-version.md)] -->
Value
Rule IDRDG013
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 that contains an invalid combination of service source attributes.

Rule description

ASP.NET Core supports resolving keyed and non-keyed services via dependency injection. It's not feasible to resolve a service as both keyed and non-keyed. The following code produces the diagnostic and throws a run time error with the same message:

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

How to fix violations

Resolve the target parameter as either a keyed or non-keyed service.

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagnostics/Rdg13/Program.cs" id="snippet_1f" highlight="16,21,26":::

When to suppress warnings

This warning should not be suppressed. Suppressing the warning leads to a NotSupportedException runtime exception The FromKeyedServicesAttribute is not supported on parameters that are also annotated with IFromServiceMetadata.