diff --git a/aspnetcore/fundamentals/aot/request-delegate-generator/diagnostics/rdg002.md b/aspnetcore/fundamentals/aot/request-delegate-generator/diagnostics/rdg002.md index 9a692319d2..84e683172e 100644 --- a/aspnetcore/fundamentals/aot/request-delegate-generator/diagnostics/rdg002.md +++ b/aspnetcore/fundamentals/aot/request-delegate-generator/diagnostics/rdg002.md @@ -16,43 +16,22 @@ uid: fundamentals/aot/request-delegate-generator/diagnostics/rdg002 ## Cause -This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler that cannot be statically analyzed. +This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler that can't be statically analyzed. ### Rule description -The Request Delegate Generator runs at compile-time and needs to be able to statically analyze route handlers in an application. The implementation currently only supports route handlers that are provided as lambda expression, method group references, or references to read-only fields or variables. +The Request Delegate Generator runs at compile-time and needs to be able to statically analyze route handlers in an app. The current implementation only supports route handlers that are provided as a lambda expression, method group references, or references to read-only fields or variables. -```razor -var app = WebApplication.Create(); +The following code generates the RDG002 warning because the route handler is provided as a reference to a method: -var del = Wrapper.GetTodos; -app.MapGet("/v1/todos", del); - -app.Run(); - -record Todo(int Id, string Task); - -class Wrapper -{ - public static Func GetTodos = () - => Results.Ok((List)[new Todo(1, "Write tests"), new Todo(2, "Fix tests")]); -} -``` +:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagonstics/Rdg2/Program.cs" id="snippet_1" highlight="13-14,25-00"::: ## How to fix violations -Declare the route handler using supported syntax, such as an inline lambda. -```razor -var app = WebApplication.Create(); +Declare the route handler using supported syntax, such as an inline lambda: -app.MapGet("/v1/todos", () - => Results.Ok((List)[new Todo(1, "Write tests"), new Todo(2, "Fix tests")])); - -app.Run(); - -record Todo(int Id, string Task); -``` +:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/aot/diagonstics/Rdg2/Program.cs" id="snippet_1f" highlight="13"::: ## When to suppress warnings -This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime. +This warning can be safely suppressed. When suppressed, the framework falls back to generating the request delegate at runtime.