Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions aspnetcore/diagnostics/asp0015.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "ASP0015: Suggest using IHeaderDictionary properties"
description: "Learn about analysis rule ASP0015: Suggest using IHeaderDictionary properties"
author: tdykstra
monikerRange: '>= aspnetcore-8.0'
ms.author: tdykstra
ms.date: 11/23/2022
uid: diagnostics/asp0015
---
# ASP0015: Suggest using IHeaderDictionary properties

| | Value |
|-|-|
| **Rule ID** |ASP0015|
| **Category** |Usage|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

[IHeaderDictionary](xref:System.Collections.IDictionary) properties are the recommended strategy for accessing headers.

## Rule description

`IHeaderDictionary` properties are recommended for accessing headers. Accessing headers using an indexer as in the example below is not recommended.

```csharp
var app = WebApplication.Create();

app.MapGet("/", (HttpContext context) => context.Request.Headers[""content-type""]);

app.Run();
```

## How to fix violations

To fix a violation of this rule, use the property specified in the analyzer message to access the header specified in the message or apply the associated codefix.

```csharp
var app = WebApplication.Create();
app.MapGet("/", (HttpContext context) => context.Request.Headers.ContentType);
app.Run();
```

## When to suppress warnings

Do not suppress a warning from this rule.
43 changes: 43 additions & 0 deletions aspnetcore/diagnostics/asp0016.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: "ASP0016: Do not return a value from RequestDelegate"
description: "Learn about analysis rule ASP0016: Do not return a value from RequestDelegate"
author: tdykstra
monikerRange: '>= aspnetcore-8.0'
ms.author: tdykstra
ms.date: 11/22/2022
uid: diagnostics/asp0016
---
# ASP0016: Do not return a value from RequestDelegate

| | Value |
|-|-|
| **Rule ID** |ASP0016|
| **Category** |Usage|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

A method used to create a <xref:Microsoft.AspNetCore.Http.RequestDelegate> returns `Task<T>`. `RequestDelegate` discards this value.

## Rule description

Do not return a value `Delegate`s provided to APIs that expect `RequestDelegate`. For example, the following sample returns a `Task<string>` where the `string` value of the `Task` will be discarded.

```csharp
var app = WebApplication.Create();
app.Use(next =>
{
return new RequestDelegate((HttpContext context) =>
{
return Task.FromResult(""hello world"");
});
});
```

## How to fix violations

To fix a violation of this rule, change the return type to non-generic `Task` or, if the delegate is a route handler, cast it to `Delegate` so the return value is written to the response.

## When to suppress warnings

Do not suppress a warning from this rule.
38 changes: 38 additions & 0 deletions aspnetcore/diagnostics/asp0017.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "ASP0017: Invalid route pattern"
description: "Learn about analysis rule ASP0017: Invalid route pattern"
author: tdykstra
monikerRange: '>= aspnetcore-8.0'
ms.author: tdykstra
ms.date: 11/22/2022
uid: diagnostics/asp0017
---
# ASP0017: Invalid route pattern

| | Value |
|-|-|
| **Rule ID** |ASP0017|
| **Category** |Usage|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

A route pattern is invalid.

## Rule description

This diagnostic is emitted when a route pattern is invalid. In the example below, the route pattern contains an invalid token.

```csharp
var app = WebApplication.Create();

app.MapGet("/{id", (int id) => ...);
```

## How to fix violations

To fix a violation of this rule, correct the error identified in the analyzer message.

## When to suppress warnings

Do not suppress a warning from this rule.
38 changes: 38 additions & 0 deletions aspnetcore/diagnostics/asp0018.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "ASP0018: Unused route parameter"
description: "Learn about analysis rule ASP0018: Unused route parameter"
author: tdykstra
monikerRange: '>= aspnetcore-8.0'
ms.author: tdykstra
ms.date: 11/22/2022
uid: diagnostics/asp0018
---
# ASP0018: Unused route parameter

| | Value |
|-|-|
| **Rule ID** |ASP0018|
| **Category** |Usage|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

A route parameter is specified but not used.

## Rule description

A route parameter is specified but not used. In the example below, the `name` parameter is defined in the route but not in the route handler.

```csharp
var app = WebApplication.Create();

app.MapGet("/{id}", () => ...);
```

## How to fix violations

To fix a violation of this rule, remove the route parameter or add code that uses the parameter.

## When to suppress warnings

Do not suppress a warning from this rule.
32 changes: 32 additions & 0 deletions aspnetcore/diagnostics/asp0019.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: "ASP0019: Suggest using IHeaderDictionary.Append or the indexer"
description: "Learn about analysis rule ASP0019: Suggest using IHeaderDictionary.Append or the indexer"
author: tdykstra
monikerRange: '>= aspnetcore-8.0'
ms.author: tdykstra
ms.date: 11/22/2022
uid: diagnostics/asp0019
---
# ASP0019: Suggest using IHeaderDictionary.Append or the indexer

| | Value |
|-|-|
| **Rule ID** |ASP0019|
| **Category** |Usage|
| **Fix is breaking or non-breaking** |Non-breaking|

## Cause

`IDictionary.Add` isn't recommended for setting or appending headers. [`IDictionary.Add`](xref:System.Collections.IDictionary.Add%2A) throws an `ArgumentException` when attempting to add a duplicate key.

## Rule description

`IDictionary.Add` isn't recommended for setting or appending headers.

## How to fix violations

To fix a violation of this rule, use `IHeaderDictionary.Append` or the indexer to append or set headers.

## When to suppress warnings

Do not suppress a warning from this rule.
7 changes: 6 additions & 1 deletion aspnetcore/diagnostics/code-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: rick-anderson
description: Learn about source code analysis in ASP.NET Core
monikerRange: '>= aspnetcore-3.1'
ms.author: riande
ms.date: 12/17/2021
ms.date: 11/22/2022
uid: diagnostics/code-analysis
---
# Code analysis in ASP.NET Core apps
Expand All @@ -27,6 +27,11 @@ uid: diagnostics/code-analysis
| [ASP0012](xref:diagnostics/asp0012) | Non-breaking | Suggest using builder.Services over Host.ConfigureServices or WebHost.ConfigureServices |
| [ASP0013](xref:diagnostics/asp0013) | Non-breaking | Suggest switching from using Configure methods to WebApplicationBuilder.Configuration |
| [ASP0014](xref:diagnostics/asp0014) | Non-breaking | Suggest using top level route registrations |
| [ASP0015](xref:diagnostics/asp0015) | Non-breaking | Suggest using IHeaderDictionary properties |
| [ASP0016](xref:diagnostics/asp0016) | Non-breaking | Do not return a value from RequestDelegate |
| [ASP0017](xref:diagnostics/asp0017) | Non-breaking | Invalid route pattern |
| [ASP0018](xref:diagnostics/asp0018) | Non-breaking | Unused route parameter |
| [ASP0019](xref:diagnostics/asp0019) | Non-breaking | Suggest using IHeaderDictionary.Append or the indexer |
| [BL0001](xref:diagnostics/bl0001) | Breaking | Component parameter should have public setters |
| [BL0002](xref:diagnostics/bl0002) | Non-breaking | Component has multiple CaptureUnmatchedValues parameters |
| [BL0003](xref:diagnostics/bl0003) | Breaking | Component parameter with CaptureUnmatchedValues has the wrong type |
Expand Down
24 changes: 24 additions & 0 deletions aspnetcore/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,30 @@ items:
uid: diagnostics/asp0006
- name: ASP0007
uid: diagnostics/asp0007
- name: ASP0008
uid: diagnostics/asp0008
- name: ASP0009
uid: diagnostics/asp0009
- name: ASP0010
uid: diagnostics/asp0010
- name: ASP0011
uid: diagnostics/asp0011
- name: ASP0012
uid: diagnostics/asp0012
- name: ASP0013
uid: diagnostics/asp0013
- name: ASP0014
uid: diagnostics/asp0014
- name: ASP0015
uid: diagnostics/asp0015
- name: ASP0016
uid: diagnostics/asp0016
- name: ASP0017
uid: diagnostics/asp0017
- name: ASP0018
uid: diagnostics/asp0018
- name: ASP0019
uid: diagnostics/asp0019
- name: BL0001
uid: diagnostics/bl0001
- name: BL0002
Expand Down