Skip to content

.NET pitfalls

Things that compile, pass review and still break your app — HttpClient, async, nullability and other traps from real projects.

Design & architecture
11 posts1 h 12 min reading time
Start with part 1 →
  1. HttpClient — you are (still) using it wrongSocket exhaustion, DNS changes that never arrive and typed clients captured by singletons. Four HttpClient mistakes that still show up in code reviews, why they hurt, and the setup that avoids them in web apps and CLI tools.6 min read
  2. async/await pitfalls that still pass code reviewasync void, .Result, fire-and-forget, Task.WhenAll that hides exceptions and ValueTask awaited twice. Six async mistakes that look harmless, why they hurt, and the analyzers that catch them before production does.8 min read
  3. ConfigureAwait(false) in 2026 — when it still mattersHalf the codebases I see sprinkle ConfigureAwait(false) everywhere, the other half never use it, and both are sure they're right. What it actually does, why ASP.NET Core apps mostly don't need it, why libraries still do, and how to stop arguing about it in code reviews.7 min read
  4. IAsyncEnumerable done rightAsync streams are one of the nicest features in modern C#, and one of the easiest to use half-right. The cancellation token that never arrives, the stream that gets enumerated twice, the DbContext that's gone mid-stream, and when a plain Task<List<T>> is the better choice.7 min read
  5. Take nullability warnings seriouslyNullable reference types only help if the warnings mean something. How a codebase ends up with hundreds of CS8602 warnings and a "!" on every other line, the design decision that removes most null checks, and how to get from warnings to a build that refuses nulls where they don't belong.6 min read
  6. Equality in generic code — why EqualityComparer<T>.Default existsThe == operator doesn't compile for an unconstrained T, object.Equals boxes, a.Equals(b) throws on null, and NaN isn't equal to itself. What EqualityComparer<T>.Default does better, where it belongs, and where a plain == is still the clearer choice.6 min read
  7. Virtual methods — sealed by default, base by defaultEvery virtual method is a promise you'll have to keep, and every override that skips base is a behaviour change, whether anyone meant it or not. Why I seal classes by default, when a virtual method is the right extension point, and the review rule for overrides.7 min read
  8. TransactionScope and async — "must be disposed on the same thread"A TransactionScope that worked for years suddenly throws after a driver upgrade, or the ambient transaction quietly vanishes after the first await. Why TransactionScope and async don't mix by default, the one option that fixes it, and the other defaults (Serializable, one minute, distributed transactions) worth knowing.5 min read
  9. Immutable collections and serialization — what really round-tripsSystem.Text.Json supports immutable collections, until it suddenly says it doesn't. The default ImmutableArray that crashes, the object values that come back as JsonElement, the frozen collections nobody tested, and how to choose read-only types for your contracts.6 min read
  10. SQL IN clauses with thousands of parametersWHERE Id IN (@p0, @p1, … @p1224) works fine in the test with ten IDs and times out in production with twelve hundred. Hard parameter limits per database, why large IN lists get slow long before that, and the better options, from batching to table-valued parameters, JSON and arrays.7 min read
  11. Startup time — lazy registrations and the Lazy<T> that isn'tA large ASP.NET Core monolith needed five to seven seconds to start, and registering only the endpoints a request needs made it three to four times faster. Where startup time really goes, why the endpoint isn't the real target, and the Lazy<T> registration that looks lazy but resolves everything eagerly.7 min read