Pitfalls of Disposing Blindly When Using IDisposable Resources

Managing resources effectively in .NET is critical for both application stability and performance. In this post, we’ll explore the proper use of the IDisposable pattern, guidelines for when to dispose objects using a using statement, and some pitfalls of disposing objects blindly—such as disposing shared resources. Understanding IDisposable The IDisposable interface provides a standardized way … →

 

REST API Best Practices in ASP.NET Core: A Practical Guide

Most REST API bugs are mundane. A mobile app on a weak connection retries a POST, and the customer ends up with two orders. An endpoint returns 200 OK with “success”: false in the body, so every client has to parse a message string to learn that something failed. Someone renames a JSON field on … →

 

C# Logging Best Practices to Improve Troubleshooting

Designing methods with a focus on logging and exception handling is crucial for building maintainable and debuggable software. In this post, we’ll discuss some C# logging best practices about designing method in a way that gives us the most level of details. A lot of time we see that an error happens in our software, … →

 

C# Coding Conventions: Adapting a Standard to Your Team

When a team decides it needs a coding convention, the usual move is to borrow one from a big company, such as Microsoft’s C# conventions, the Airbnb JavaScript guide or one of Google’s style guides. That’s a sensible starting point. But each of those documents was written for one company’s team size, codebase and tools. … →

 

ASP.NET Core Best Practices: A Performance Quick Reference

ASP.NET Core is fast by default, and most of the slowdowns in real apps trace back to a handful of habits: blocking on async code, loading too much data in one go, and putting heavy work on code that runs for every request. This post collects those ASP.NET Core best practices in one place, along … →

 

SP.NET Core, React and Database Security Best Practices

This is the security checklist I go through on the stacks I’ve used most as a developer: ASP.NET Core and .NET, REST APIs, React and npm, and SQL and NoSQL databases. Each section is short enough to skim before a release or a code review. Where the right setting isn’t obvious, there’s a small code … →

 

Programming Principles: DRY, KISS, SOLID, YAGNI and More

I’ve written before about the principle I use most when designing software, doing the simplest thing that could possibly work. This post collects the other programming principles and laws I keep returning to, from DRY and SOLID to Conway’s law and Brooks’s law. None of them can be applied mechanically, and several pull against each … →

 

C# Exception Handling Best Practices: A Quick Reference

I’ve written about .NET exceptions twice before: once on exception handling best practices in general, and once on exception handling in asynchronous code. Both are long, and sometimes you just want the rule without the essay. This post is the short version: the practices from those articles plus a few newer ones, grouped by situation, … →

 

Entity Framework Core and LINQ Best Practices for C#

Entity Framework makes data access easy to write, and that’s also what makes it easy to write badly. A query that’s instant against a few test rows can bring the database to a crawl once it hits production data, and the C# often looks perfectly fine. This is my reference list of LINQ and Entity … →

 

C# Async and Parallel Programming Best Practices

I’ve written about asynchronous and parallel programming before, in the seven most common async mistakes and what SynchronizationContext is. Few topics in C# produce as many subtle bugs. Deadlocks only show up on the UI thread, exceptions disappear from async void methods, and race conditions never happen on your machine and happen every day in … →