csharp

Identify and prevent production C# pitfalls like async/await deadlocks and nullability mistakes.

13|Updated Mar 15, 2019
One-click install
npx skills add https://github.com/WTFox/dotfiles --skill csharp-wtfox
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp
Source: https://github.com/WTFox/dotfiles/tree/main/claude/.claude/skills/csharp
Command: npx skills add https://github.com/WTFox/dotfiles --skill csharp-wtfox

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers avoid and remediate the most dangerous, production-grade C# pitfalls that show up in real-world code, such as async/await deadlocks, improper cancellation propagation, nullable reference type pitfalls, DI mispatterns, and LINQ vs loops, ensuring more reliable and maintainable software.

Core Features & Use Cases

  • Async/Await correctness: guides on avoiding deadlocks, proper async all the way, and avoiding .Result/.Wait in production ASP.NET Core apps.
  • Cancellation and DI patterns: propagation of CancellationToken through layers and constructor injection for testability.
  • Robust nullability and types: enabling nullable reference types and using required/init for safe state.
  • Records vs Classes guidance: using records for immutable data and classes for entities with identity.
  • Disposal and logging best practices: modern using declarations and structured logging.

Quick Start

Read this guide before writing or reviewing any production C# code to apply the patterns consistently.

Frequently Asked Questions about csharp

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent async/await deadlocks in ASP.NET Core production code?

Prevent async/await deadlocks by avoiding .Result or .Wait() in production ASP.NET Core apps and ensuring async flows all the way through call chains. Library code should apply ConfigureAwait(false) to avoid synchronization context capture.

What is the proper way to propagate CancellationToken through service layers in C#?

Proper CancellationToken propagation threads the token through every asynchronous method signature and layer, ensuring data access methods and I/O operations receive and respect the token for safe cancellation.

How should I use nullable reference types and required properties for safe state?

Enable nullable reference types and use required or init properties to enforce safe state initialization at compile time. This prevents nullability pitfalls and guarantees immutable data structures are fully populated.

When do I use records versus classes for data structures in C#?

Use records for immutable data transfer objects where value equality matters, and use classes for entities with identity and mutable state. This distinction ensures maintainable and reliable domain models.

Does this C# guidance apply to dependency injection patterns in EF Core?

Yes, this guidance applies to EF Core by enforcing constructor-based dependency injection for testability. It ensures data access contexts and services are properly injected rather than manually instantiated.

What are the limitations of using .Result or .Wait in asynchronous I/O operations?

Using .Result or .Wait in asynchronous I/O operations causes thread pool starvation and deadlocks by blocking the calling thread. These limitations make synchronous blocking highly discouraged in production C# environments.