Skip to content

Commit a4db169

Browse files
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>
1 parent a867841 commit a4db169

File tree

13 files changed

+716
-0
lines changed

13 files changed

+716
-0
lines changed

aspnetcore/diagnostics/rdg001.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "RDG001: Unable to resolve route pattern"
3+
description: "Learn about analysis rule RDG001: Unable to resolve route pattern"
4+
author: captainsafia
5+
monikerRange: '>= aspnetcore-8.0'
6+
ms.author: safia
7+
ms.date: 09/15/2023
8+
uid: aot/request-delegate-generator/diagnostics/rdg001
9+
---
10+
# RDG001: Unable to resolve route pattern
11+
12+
| | Value |
13+
|-|-|
14+
| **Rule ID** |RDG001|
15+
| **Fix is breaking or non-breaking** |Non-breaking|
16+
17+
## Cause
18+
19+
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.
20+
21+
### Rule description
22+
23+
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.
24+
25+
```razor
26+
var app = WebApplication.Create();
27+
28+
var version = "v1";
29+
var route = $"/{version}/todos";
30+
31+
app.MapGet(route, () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
32+
33+
app.Run();
34+
35+
record Todo(int Id, string Task);
36+
```
37+
38+
## How to fix violations
39+
40+
Declare the route pattern as an inline string literal in the route handler.
41+
```razor
42+
var app = WebApplication.Create();
43+
44+
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
45+
46+
app.Run();
47+
48+
record Todo(int Id, string Task);
49+
```
50+
51+
## When to suppress warnings
52+
53+
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

aspnetcore/diagnostics/rdg002.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: "RDG002: Unable to resolve endpoint handler"
3+
description: "Learn about analysis rule RDG002: Unable to resolve endpoint handler"
4+
author: captainsafia
5+
monikerRange: '>= aspnetcore-8.0'
6+
ms.author: safia
7+
ms.date: 09/15/2023
8+
uid: aot/request-delegate-generator/diagnostics/rdg002
9+
---
10+
# RDG002: Unable to resolve endpoint handler
11+
12+
| | Value |
13+
|-|-|
14+
| **Rule ID** |RDG002|
15+
| **Fix is breaking or non-breaking** |Non-breaking|
16+
17+
## Cause
18+
19+
This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler that cannot be statically analyzed.
20+
21+
### Rule description
22+
23+
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.
24+
25+
```razor
26+
var app = WebApplication.Create();
27+
28+
var del = Wrapper.GetTodos;
29+
app.MapGet("/v1/todos", del);
30+
31+
app.Run();
32+
33+
record Todo(int Id, string Task);
34+
35+
class Wrapper
36+
{
37+
public static Func<IResult> GetTodos = ()
38+
=> Results.Ok((List<Todo>)[new Todo(1, "Write tests"), new Todo(2, "Fix tests")]);
39+
}
40+
```
41+
42+
## How to fix violations
43+
44+
Declare the route handler using supported syntax, such as an inline lambda.
45+
```razor
46+
var app = WebApplication.Create();
47+
48+
app.MapGet("/v1/todos", ()
49+
=> Results.Ok((List<Todo>)[new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
50+
51+
app.Run();
52+
53+
record Todo(int Id, string Task);
54+
```
55+
56+
## When to suppress warnings
57+
58+
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

aspnetcore/diagnostics/rdg003.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "RDG003: Unable to resolve parameter"
3+
description: "Learn about analysis rule RDG003: Unable to resolve parameter"
4+
author: captainsafia
5+
monikerRange: '>= aspnetcore-8.0'
6+
ms.author: safia
7+
ms.date: 09/15/2023
8+
uid: aot/request-delegate-generator/diagnostics/rdg003
9+
---
10+
# RDG003: Unable to resolve parameter
11+
12+
| | Value |
13+
|-|-|
14+
| **Rule ID** |RDG003|
15+
| **Fix is breaking or non-breaking** |Non-breaking|
16+
17+
## Cause
18+
19+
This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler with a parameter that cannot be statically analyzed.
20+
21+
### Rule description
22+
23+
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
24+
25+
```razor
26+
var app = WebApplication.Create();
27+
28+
var version = "v1";
29+
var route = $"/{version}/todos";
30+
31+
app.MapGet("/vl/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
32+
33+
app.Run();
34+
35+
record Todo(int Id, string Task);
36+
```
37+
38+
## How to fix violations
39+
40+
Declare the route pattern as an inline string literal in the route handler.
41+
```razor
42+
var app = WebApplication.Create();
43+
44+
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
45+
46+
app.Run();
47+
48+
record Todo(int Id, string Task);
49+
```
50+
51+
## When to suppress warnings
52+
53+
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

aspnetcore/diagnostics/rdg004.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "RDG004: Unable to resolve anonymous type"
3+
description: "Learn about analysis rule RDG004: Unable to resolve anonymous type"
4+
author: captainsafia
5+
monikerRange: '>= aspnetcore-8.0'
6+
ms.author: safia
7+
ms.date: 09/15/2023
8+
uid: aot/request-delegate-generator/diagnostics/rdg004
9+
---
10+
# RDG004: Unable to resolve anonymous type
11+
12+
| | Value |
13+
|-|-|
14+
| **Rule ID** |RDG004|
15+
| **Fix is breaking or non-breaking** |Non-breaking|
16+
17+
## Cause
18+
19+
This diagnostic is emitted by the Request Delegate Generator when an endpoint contains a route handler with an anonymous return type.
20+
21+
### Rule description
22+
23+
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.
24+
25+
```razor
26+
var app = WebApplication.Create();
27+
28+
app.MapGet("/v1/todos", () => new { Id = 1, Task = "Write tests" });
29+
30+
app.Run();
31+
```
32+
33+
## How to fix violations
34+
35+
Declare the route handler with a concrete type as the return type.
36+
```razor
37+
var app = WebApplication.Create();
38+
39+
app.MapGet("/v1/todos", () => new Todo(1, "Write tests");
40+
41+
app.Run();
42+
43+
record Todo(int Id, string Task);
44+
```
45+
46+
## When to suppress warnings
47+
48+
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

aspnetcore/diagnostics/rdg005.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "RDG005: Unable to resolve anonymous type"
3+
description: "Learn about analysis rule RDG005: Unable to resolve anonymous type"
4+
author: captainsafia
5+
monikerRange: '>= aspnetcore-8.0'
6+
ms.author: safia
7+
ms.date: 09/15/2023
8+
uid: aot/request-delegate-generator/diagnostics/rdg005
9+
---
10+
# RDG005: Invalid abstract type
11+
12+
| | Value |
13+
|-|-|
14+
| **Rule ID** |RDG005|
15+
| **Fix is breaking or non-breaking** |Non-breaking|
16+
17+
## Cause
18+
19+
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.
20+
21+
### Rule description
22+
23+
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.
24+
25+
```razor
26+
var app = WebApplication.Create();
27+
28+
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest todoRequest) => Results.Ok(todoRequest.Todo));
29+
30+
app.Run();
31+
32+
abstract class TodoRequest
33+
{
34+
public int Id { get; set; }
35+
public Todo? Todo { get; set; }
36+
}
37+
38+
record Todo(int Id, string Task);
39+
```
40+
41+
## How to fix violations
42+
43+
Use a concrete type for the surrogate.
44+
```razor
45+
var app = WebApplication.Create();
46+
47+
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest todoRequest) => Results.Ok(todoRequest.Todo));
48+
49+
app.Run();
50+
51+
class TodoRequest
52+
{
53+
public int Id { get; set; }
54+
public Todo? Todo { get; set; }
55+
}
56+
57+
record Todo(int Id, string Task);
58+
```
59+
60+
## When to suppress warnings
61+
62+
This warning should not be suppressed. Suppressing the warning will lead to a runtime exception assocaited with the same warning.

aspnetcore/diagnostics/rdg006.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "RDG006: Invalid constructor parameters"
3+
description: "Learn about analysis rule RDG006: Invalid constructor parameters"
4+
author: captainsafia
5+
monikerRange: '>= aspnetcore-8.0'
6+
ms.author: safia
7+
ms.date: 09/15/2023
8+
uid: aot/request-delegate-generator/diagnostics/rdg006
9+
---
10+
# RDG006: Invalid constructor parameters
11+
12+
| | Value |
13+
|-|-|
14+
| **Rule ID** |RDG006|
15+
| **Fix is breaking or non-breaking** |Non-breaking|
16+
17+
## Cause
18+
19+
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.
20+
21+
### Rule description
22+
23+
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.
24+
25+
```razor
26+
var app = WebApplication.Create();
27+
28+
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest todoRequest) => Results.Ok(todoRequest.Todo));
29+
30+
app.Run();
31+
32+
class TodoRequest(int id, string name)
33+
{
34+
public int Id { get; set; } = id;
35+
public Todo? Todo { get; set; }
36+
}
37+
38+
record Todo(int Id, string Task);
39+
```
40+
41+
## How to fix violations
42+
43+
Ensure that all properties on the type have a match parameter on the constructor.
44+
```razor
45+
var app = WebApplication.Create();
46+
47+
app.MapPut("/v1/todos/{id}", ([AsParameters] TodoRequest todoRequest) => Results.Ok(todoRequest.Todo));
48+
49+
app.Run();
50+
51+
class TodoRequest(int id, Todo? todo)
52+
{
53+
public int Id { get; set; } = id;
54+
public Todo? Todo { get; set; } = todo;
55+
}
56+
57+
record Todo(int Id, string Task);
58+
```
59+
60+
## When to suppress warnings
61+
62+
This warning should not be suppressed. Suppressing the warning will lead to a runtime exception assocaited with the same warning.

aspnetcore/diagnostics/rdg007.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "RDG007: No valid constructor found"
3+
description: "Learn about analysis rule RDG007: No valid constructor found"
4+
author: captainsafia
5+
monikerRange: '>= aspnetcore-8.0'
6+
ms.author: safia
7+
ms.date: 09/15/2023
8+
uid: aot/request-delegate-generator/diagnostics/rdg007
9+
---
10+
# RDG007: No valid constructor found
11+
12+
| | Value |
13+
|-|-|
14+
| **Rule ID** |RDG007|
15+
| **Fix is breaking or non-breaking** |Non-breaking|
16+
17+
## Cause
18+
19+
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.
20+
21+
### Rule description
22+
23+
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.
24+
25+
```razor
26+
var app = WebApplication.Create();
27+
28+
var version = "v1";
29+
var route = $"/{version}/todos";
30+
31+
app.MapGet("/vl/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
32+
33+
app.Run();
34+
35+
record Todo(int Id, string Task);
36+
```
37+
38+
## How to fix violations
39+
40+
Declare the route pattern as an inline string literal in the route handler.
41+
```razor
42+
var app = WebApplication.Create();
43+
44+
app.MapGet("/v1/todos", () => Results.Ok([new Todo(1, "Write tests"), new Todo(2, "Fix tests")]));
45+
46+
app.Run();
47+
48+
record Todo(int Id, string Task);
49+
```
50+
51+
## When to suppress warnings
52+
53+
This warning can be safely suppressed. When suppressed, the framework will fallback to generating the request delegate at runtime.

0 commit comments

Comments
 (0)