Dotnet Csharp Code Smells logo

Dotnet Csharp Code Smells

Community
wshaddix
dotnet-csharp-code-smells

Reviewing C# for logic issues. Anti-patterns, common pitfalls, async misuse, DI mistakes.

Overview

Publisherwshaddix
Repositorydotnet-skills
Skill namedotnet-csharp-code-smells
Stars
79
Forks
13
Bundled files
1
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by wshaddix on GitHub. Read the source before you install it.

Installation

Install the Dotnet Csharp Code Smells AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wshaddix/dotnet-skills.git /tmp/dotnet-skills
mkdir -p .claude/skills
cp -r /tmp/dotnet-skills/skills/dotnet-csharp-code-smells .claude/skills/dotnet-csharp-code-smells
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Dotnet Csharp Code Smells in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Dotnet Csharp Code Smells on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Dotnet Csharp Code Smells is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

dotnet-csharp-code-smells

Proactive code-smell and anti-pattern detection for C# code. This skill triggers during all workflow modes -- planning, implementation, and review. Each entry identifies the smell, explains why it is harmful, provides the correct fix, and references the relevant CA rule or cross-reference.

Cross-references: [skill:dotnet-csharp-async-patterns] for async gotchas, [skill:dotnet-csharp-coding-standards] for naming and style, [skill:dotnet-csharp-dependency-injection] for DI lifetime misuse, [skill:dotnet-csharp-nullable-reference-types] for NRT annotation mistakes.

Out of Scope: LLM-specific generation mistakes (wrong NuGet packages, bad project structure, MSBuild errors) are covered by [skill:dotnet-agent-gotchas]. This skill covers general .NET code smells that any developer -- human or AI -- should avoid.


1. Resource Management (IDisposable Misuse)

SmellWhy HarmfulFixRule
Missing using on disposable localsLeaks unmanaged handles (sockets, files, DB connections)Wrap in using declaration or using blockCA2000
Undisposed IDisposable fieldsClass holds disposable resource but never disposes itImplement IDisposable; dispose fields in Dispose()CA2213
Wrong Dispose pattern (no finalizer guard)Double-dispose or missed cleanup on GC finalizationFollow canonical Dispose(bool) pattern; call GC.SuppressFinalize(this)CA1816
Disposable created in one method, stored in fieldOwnership unclear; easy to forget disposalDocument ownership; make the containing class IDisposableCA2000
using on non-owned resourcePremature disposal of shared resource (e.g., injected HttpClient)Only dispose resources you create; let DI manage injected services--

See details.md for code examples of each pattern.


2. Warning Suppression Hacks

SmellWhy HarmfulFixRule
Invoking event with null to suppress CS0067Creates misleading runtime behavior; masks real bugsUse #pragma warning disable CS0067 or explicit event accessors { add {} remove {} }CS0067
Dummy variable assignments to suppress CS0219Dead code that confuses readersUse _ = expression; discard or #pragma warning disableCS0219
Blanket #pragma warning disable without restoreSuppresses ALL warnings for rest of fileAlways pair with #pragma warning restore; suppress specific codes only--
[SuppressMessage] without justificationFuture maintainers cannot evaluate if suppression is still validAlways include Justification = "reason"CA1303

See details.md for the CS0067 motivating example (bad pattern to correct fix).


3. LINQ Anti-Patterns

SmellWhy HarmfulFixRule
Premature .ToList() mid-chainForces full materialization; wastes memoryKeep chain lazy; materialize only at the endCA1851
Multiple enumeration of IEnumerable<T>Re-executes query or DB call on each enumerationMaterialize once with .ToList() then reuseCA1851
Client-side evaluation in EF CoreLoads entire table into memory; silent perf bombRewrite query as translatable LINQ or use AsAsyncEnumerable() with explicit intent--
.Count() > 0 instead of .Any()Enumerates entire collection instead of short-circuitingUse .Any() for existence checksCA1827
Nested foreach instead of .Join() or .GroupJoin()O(n*m) when O(n+m) is possibleUse LINQ join operations or Dictionary lookup--
.Where().First() instead of .First(predicate)Creates unnecessary intermediate iteratorPass predicate directly to .First() or .FirstOrDefault()CA1826

4. Event Handling Leaks

SmellWhy HarmfulFixRule
Not unsubscribing from eventsMemory leak: publisher holds reference to subscriberUnsubscribe in Dispose() or use weak event pattern--
Raising events in constructorSubscribers may not be attached yet; derived class not fully constructedRaise events only from fully initialized instancesCA2214
async void event handler (misused)async void is the only valid signature for event handlers, but exceptions are unobservableWrap body in try/catch; log and handle exceptions explicitly--
Event handler not checking for nullNullReferenceException when no subscribersUse event?.Invoke() null-conditional pattern--
Static event without cleanupRooted references prevent GC for application lifetimePrefer instance events or use WeakEventManager--

Cross-reference: [skill:dotnet-csharp-async-patterns] covers async void fire-and-forget patterns in depth.


5. Design Smells

SmellThresholdWhy HarmfulFix
God class>500 linesToo many responsibilities; hard to test and maintainExtract cohesive classes using SRP
Long method>30 linesHard to understand, test, and reviewExtract helper methods with descriptive names
Long parameter list>5 parametersIndicates missing abstractionIntroduce parameter object or builder
Feature envyMethod uses another class's data more than its ownMisplaced responsibility; tight couplingMove method to the class it envies
Primitive obsessionDomain concepts represented as raw string/intNo type safety; validation scatteredIntroduce value objects or strongly-typed IDs
Deep nesting>3 levels of indentationHard to follow control flowUse guard clauses (early return) and extract methods

6. Exception Handling Gaps

SmellWhy HarmfulFixRule
Empty catch blockSilently swallows errors; masks bugsAt minimum, log the exception; prefer letting it propagateCA1031
Catching base ExceptionCatches OutOfMemoryException, StackOverflowException, etc.Catch specific exception typesCA1031
Log-and-swallow (catch { log; })Caller never learns operation failedRe-throw after logging, or return error result--
Throwing in finallyMasks original exception with the new oneUse try/catch inside finally; never throw from finally--
throw ex; instead of throw;Resets stack trace; hides original failure locationUse bare throw; to preserve stack traceCA2200
Not including inner exceptionLoses causal chain when wrapping exceptionsPass original as innerException parameter--

Cross-reference: [skill:dotnet-csharp-async-patterns] covers exception handling in fire-and-forget and async void scenarios.


Quick Reference: CA Rules

RuleDescription
CA1031Do not catch general exception types
CA1816Call GC.SuppressFinalize correctly
CA1826Do not use Enumerable methods on indexable collections
CA1827Do not use Count()/LongCount() when Any() can be used
CA1851Possible multiple enumerations of IEnumerable collection
CA2000Dispose objects before losing scope
CA2200Rethrow to preserve stack details
CA2213Disposable fields should be disposed
CA2214Do not call overridable methods in constructors

Enable these via <AnalysisLevel>latest-all</AnalysisLevel> in your project. See [skill:dotnet-csharp-coding-standards] for analyzer configuration.


References

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Dotnet Csharp Code Smells AI skill do?

Reviewing C# for logic issues. Anti-patterns, common pitfalls, async misuse, DI mistakes.

Why use Dotnet Csharp Code Smells on TypingMind?

Because you install it once and use it with any model. Dotnet Csharp Code Smells is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Dotnet Csharp Code Smells in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/wshaddix/dotnet-skills/tree/master/skills/dotnet-csharp-code-smells. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Dotnet Csharp Code Smells?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Dotnet Csharp Code Smells?

As many as you like. As long as a model supports skills, you can use Dotnet Csharp Code Smells with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Dotnet Csharp Code Smells AI skill free?

It is published on GitHub by wshaddix. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇