Dump some content (#30446)

* Dump some content

* Update aspnetcore/diagnostics/rdg005.md

* Update aspnetcore/diagnostics/rdg007.md

* Update aspnetcore/diagnostics/rdg005.md

---------

Co-authored-by: Safia Abdalla <safia@safia.rocks>
pull/30453/head
Rick Anderson 2023-09-22 12:20:57 -10:00 committed by GitHub
parent a867841995
commit a4db169117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 716 additions and 0 deletions

View File

@ -0,0 +1,53 @@
---
title: "RDG001: Unable to resolve route pattern"
description: "Learn about analysis rule RDG001: Unable to resolve route pattern"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg001
---
# RDG001: Unable to resolve route pattern
| | Value |
|-|-|
| **Rule ID** |RDG001|
| **Fix is breaking or non-breaking** |Non-breaking|
## Cause
This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route pattern that cannot be statically analyzed including route patterns that contain variable references.
### 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 does not currently support flow analysis to understand references to route pattern store in variables. The endpoint defined in the following application will produce the RDG001 diagnostic.
```razor
var app = WebApplication.Create();
var version = "v1";
var route = $"/{version}/todos";
app.MapGet(route, () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## How to fix violations
Declare the route pattern as an inline string literal in the route handler.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,58 @@
---
title: "RDG002: Unable to resolve endpoint handler"
description: "Learn about analysis rule RDG002: Unable to resolve endpoint handler"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg002
---
# RDG002: Unable to resolve endpoint handler
| | Value |
|-|-|
| **Rule ID** |RDG002|
| **Fix is breaking or non-breaking** |Non-breaking|
## Cause
This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler that cannot 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.
```razor
var app = WebApplication.Create();
var del = Wrapper.GetTodos;
app.MapGet("/v1/todos", del);
app.Run();
record Todo(int Id, string Task);
class Wrapper
{
public static Func<IResult> GetTodos = ()
=> Results.Ok((List<Todo>)[new Todo(1, "Write tests"), new Todo(2, "Fix tests")]);
}
```
## How to fix violations
Declare the route handler using supported syntax, such as an inline lambda.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", ()
=> Results.Ok((List<Todo>)[new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,53 @@
---
title: "RDG003: Unable to resolve parameter"
description: "Learn about analysis rule RDG003: Unable to resolve parameter"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg003
---
# RDG003: Unable to resolve parameter
| | Value |
|-|-|
| **Rule ID** |RDG003|
| **Fix is breaking or non-breaking** |Non-breaking|
## Cause
This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler with a parameter that cannot 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. This diagnostic is emitted when the
```razor
var app = WebApplication.Create();
var version = "v1";
var route = $"/{version}/todos";
app.MapGet("/vl/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## How to fix violations
Declare the route pattern as an inline string literal in the route handler.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,48 @@
---
title: "RDG004: Unable to resolve anonymous type"
description: "Learn about analysis rule RDG004: Unable to resolve anonymous type"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg004
---
# RDG004: Unable to resolve anonymous type
| | Value |
|-|-|
| **Rule ID** |RDG004|
| **Fix is breaking or non-breaking** |Non-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 application. Anonymous types are generated with an unspeakable type name and are not statically analyzable. The following endpoint will produce the diagnostic.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => new { Id = 1, Task = "Write tests" });
app.Run();
```
## How to fix violations
Declare the route handler with a concrete type as the return type.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => new Todo(1, "Write tests");
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,62 @@
---
title: "RDG005: Unable to resolve anonymous type"
description: "Learn about analysis rule RDG005: Unable to resolve anonymous type"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg005
---
# RDG005: Invalid abstract type
| | Value |
|-|-|
| **Rule ID** |RDG005|
| **Fix is breaking or non-breaking** |Non-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 sample below will produce the diagnostic.
```razor
var app = WebApplication.Create();
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest todoRequest) => Results.Ok(todoRequest.Todo));
app.Run();
abstract class TodoRequest
{
public int Id { get; set; }
public Todo? Todo { get; set; }
}
record Todo(int Id, string Task);
```
## How to fix violations
Use a concrete type for the surrogate.
```razor
var app = WebApplication.Create();
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest todoRequest) => Results.Ok(todoRequest.Todo));
app.Run();
class TodoRequest
{
public int Id { get; set; }
public Todo? Todo { get; set; }
}
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning should not be suppressed. Suppressing the warning will lead to a runtime exception assocaited with the same warning.

View File

@ -0,0 +1,62 @@
---
title: "RDG006: Invalid constructor parameters"
description: "Learn about analysis rule RDG006: Invalid constructor parameters"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg006
---
# RDG006: Invalid constructor parameters
| | Value |
|-|-|
| **Rule ID** |RDG006|
| **Fix is breaking or non-breaking** |Non-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 contains an invalid constructor.
### Rule description
Types that are used for surrogate binding via the `AsParameters` attribute must contain a public parameterized constructor where all parameters to the constructor match the public properties declared on the type. The `TodoRequest` type will produce this diagnostic because there is no matching constructor parameter for the `Todo` property.
```razor
var app = WebApplication.Create();
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest todoRequest) => Results.Ok(todoRequest.Todo));
app.Run();
class TodoRequest(int id, string name)
{
public int Id { get; set; } = id;
public Todo? Todo { get; set; }
}
record Todo(int Id, string Task);
```
## How to fix violations
Ensure that all properties on the type have a match parameter on the constructor.
```razor
var app = WebApplication.Create();
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest todoRequest) => Results.Ok(todoRequest.Todo));
app.Run();
class TodoRequest(int id, Todo? todo)
{
public int Id { get; set; } = id;
public Todo? Todo { get; set; } = todo;
}
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning should not be suppressed. Suppressing the warning will lead to a runtime exception assocaited with the same warning.

View File

@ -0,0 +1,53 @@
---
title: "RDG007: No valid constructor found"
description: "Learn about analysis rule RDG007: No valid constructor found"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg007
---
# RDG007: No valid constructor found
| | Value |
|-|-|
| **Rule ID** |RDG007|
| **Fix is breaking or non-breaking** |Non-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 no valid constructor.
### Rule description
Types that are used for surrogate binding via the `AsParameters` attribute must contain a public parameterized constructor where all parameters to the constructor match the public properties declared on the type. The `TodoRequest` type will produce this diagnostic because there is no matching constructor parameter for the `Project` property.
```razor
var app = WebApplication.Create();
var version = "v1";
var route = $"/{version}/todos";
app.MapGet("/vl/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## How to fix violations
Declare the route pattern as an inline string literal in the route handler.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,53 @@
---
title: "RDG008: Multiple public constructors"
description: "Learn about analysis rule RDG008: Multiple public constructors"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg008
---
# RDG008: Multiple public constructors
| | Value |
|-|-|
| **Rule ID** |RDG008|
| **Fix is breaking or non-breaking** |Non-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 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.
```razor
var app = WebApplication.Create();
var version = "v1";
var route = $"/{version}/todos";
app.MapGet("/vl/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## How to fix violations
Declare the route pattern as an inline string literal in the route handler.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,53 @@
---
title: "RDG009: Invalid nested AsParameters"
description: "Learn about analysis rule RDG009: Invalid nested AsParameters"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg009
---
# RDG009: Invalid nested AsParameters
| | Value |
|-|-|
| **Rule ID** |RDG009|
| **Fix is breaking or non-breaking** |Non-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 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.
```razor
var app = WebApplication.Create();
var version = "v1";
var route = $"/{version}/todos";
app.MapGet("/vl/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## How to fix violations
Declare the route pattern as an inline string literal in the route handler.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,53 @@
---
title: "RDG010: Unexpected nullable type"
description: "Learn about analysis rule RDG010: Unexpected nullable type"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg010
---
# RDG010: Unexpected nullable type
| | Value |
|-|-|
| **Rule ID** |RDG010|
| **Fix is breaking or non-breaking** |Non-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 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.
```razor
var app = WebApplication.Create();
var version = "v1";
var route = $"/{version}/todos";
app.MapGet("/vl/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## How to fix violations
Declare the route pattern as an inline string literal in the route handler.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,53 @@
---
title: "RDG011: Type parameters not supported"
description: "Learn about analysis rule RDG011: Type parameters not supported"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg011
---
# RDG011: Type parameters not supported
| | Value |
|-|-|
| **Rule ID** |RDG011|
| **Fix is breaking or non-breaking** |Non-breaking|
## Cause
This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler that captures a generic type.
### 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.
```razor
var app = WebApplication.Create();
var version = "v1";
var route = $"/{version}/todos";
app.MapGet("/vl/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## How to fix violations
Declare the route pattern as an inline string literal in the route handler.
```razor
var app = WebApplication.Create();
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
app.Run();
record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,52 @@
---
title: "RDG012: Unable to resolve inaccessible type"
description: "Learn about analysis rule RDG012: Unable to resolve inaccessible type"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg012
---
# RDG012: Unable to resolve inaccessible type
| | Value |
|-|-|
| **Rule ID** |RDG012|
| **Fix is breaking or non-breaking** |Non-breaking|
## Cause
This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler with a parameter without the appropriate accessibility modifiers.
### Rule description
The Request Delegate Generator only supports
```csharp
var app = WebApplication.Create();
app.MapPost("/vl/todos", (Todo todo)
=> Results.Created(todo));
app.Run();
private record Todo(int Id, string Task);
```
## How to fix violations
When applicable, set the target parameter type with a friendly accessibility.
```csharp
var app = WebApplication.Create();
app.MapPost("/vl/todos", (Todo todo)
=> Results.Created(todo));
app.Run();
public record Todo(int Id, string Task);
```
## When to suppress warnings
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

View File

@ -0,0 +1,63 @@
---
title: "RDG013: Invalid source attributes"
description: "Learn about analysis rule RDG013: Invalid source attributes"
author: captainsafia
monikerRange: '>= aspnetcore-8.0'
ms.author: safia
ms.date: 09/15/2023
uid: aot/request-delegate-generator/diagnostics/rdg013
---
# RDG013: Invalid source attributes
| | Value |
|-|-|
| **Rule ID** |RDG013|
| **Fix is breaking or non-breaking** |Non-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 serivce source attributes.
### Rule description
ASP.NET Core supports resolving keyed and non-keyed services via dependency injection. It is not feasible to resolve a service as both keyed and non-keyed. The following code sample will produce the diagnostic.
```razor
var app = WebApplication.Create();
app.MapGet("/vl/todos", ([FromKeyedService("primary")] [FromService] ITodoService todoService)
=> Results.Ok(todoService.GetTodos()));
app.Run();
record Todo(int Id, string Task);
interface ITodoService
{
Todo[] GetTodos();
}
```
## How to fix violations
Resolve the target parameter as either a keyed or non-keyed service.
```razor
var app = WebApplication.Create();
app.MapGet("/vl/todos", ([FromKeyedService("primary")] ITodoService todoService)
=> Results.Ok(todoService.GetTodos()));
// OR
app.MapGet("/vl/todos", ([FromService] ITodoService todoService)
=> Results.Ok(todoService.GetTodos()));
app.Run();
record Todo(int Id, string Task);
interface ITodoService
{
Todo[] GetTodos();
}
```
## When to suppress warnings
This warning should not be suppressed. Suppressing the warning will lead to a runtime exception assocaited with the same warning.