Prompt library

.NET prompts

Prompts for C# and ASP.NET Core work: reviewing async code, designing endpoints, and migrating to current framework versions.

  • csharp
  • async
  • code review
100/100 · 161 tokens

C# async and await review

Reviews C# code for blocking calls, missing cancellation, and unobserved tasks.

Use it when: Reviewing a service or controller before release, when thread-pool starvation or deadlocks are a concern.

prompt
You are a senior .NET engineer reviewing asynchronous C# code.

## Task
Review the C# code below for incorrect use of async and await.

## Requirements
- Flag every call to .Result, .Wait(), or .GetAwaiter().GetResult() on a task.
- Flag every async method that accepts no CancellationToken but calls a method that takes one.
- Flag every async void method that is not an event handler.
- Report only issues you can point to in the code.
- Give the corrected line for every issue.

## Output format
Return a markdown table with the columns Line, Issue, Why it matters, and Corrected code. If there are no issues, return the single line "No async issues found."

## Input
<code>
{{code}}
</code>

Variables

{{code}}
The C# file or methods to review.

Example input

code: an OrdersController with a Get action that calls _repo.GetAsync(id).Result.

Example output

| Line | Issue | Why it matters | Corrected code |
|---|---|---|---|
| 18 | `.Result` on a task | Blocks a thread-pool thread and can deadlock | `var order = await _repo.GetAsync(id, ct);` |

Illustrative: written to show the expected shape, not generated by a model.

  • aspnet core
  • api
  • csharp
100/100 · 146 tokens

ASP.NET Core minimal API endpoint

Writes a minimal API endpoint with validation, typed results, and the status codes you specify.

Use it when: Adding an endpoint to an ASP.NET Core service and you want validation and responses handled consistently.

prompt
You are a senior .NET engineer writing ASP.NET Core minimal APIs.

## Task
Write one minimal API endpoint that implements the specification below.

## Requirements
- Use TypedResults for every response.
- Validate the request body and return 400 with a ValidationProblem for invalid input.
- Accept a CancellationToken and pass it to every awaited call.
- Use only the types and services named in the specification.
- Do not add authentication, logging, or packages the specification does not mention.

## Output format
Return one C# code block containing the endpoint mapping and its request and response records, followed by a bulleted list of the status codes it returns.

## Input
<specification>
{{specification}}
</specification>

Variables

{{specification}}
Route, method, request and response fields, the service to call, and the status codes.

Example input

specification: POST /orders, body { customerId: guid, items: [{ sku, quantity }] }, calls IOrderService.CreateAsync, returns 201 with the order id, 400 on invalid input.

Example output

```csharp
app.MapPost("/orders", async Task<Results<Created<OrderCreated>, ValidationProblem>> (CreateOrder request, IOrderService orders, CancellationToken ct) => { ... });
```
- 201 Created with the order id
- 400 with validation errors

Illustrative: written to show the expected shape, not generated by a model.

Make it yours

Edit the requirements to match your standards, then check the result. Theprompt analyzer re-scores it as you type, theoptimizer removes filler without dropping a requirement, and thesecurity scanner flags secrets and personal data before you send it to a model.

More categories