Skip to main content

Posts

System.Text.Json vs Newtonsoft: .NET 10 Migration Gotchas

Last updated: October 8, 2026 · Tested with .NET 10 (SDK 10.0.401, runtime 10.0.12), Newtonsoft.Json 13.0.4, BenchmarkDotNet 0.15.8, Windows 11 Short answer: on .NET 10, use System.Text.Json for new code and for most migrations. It ships with the runtime, it is what ASP.NET Core uses by default, and in my benchmark it serialized a 20-line order about twice as fast as Newtonsoft.Json with a quarter of the allocations. Keep Newtonsoft.Json where you depend on its leniency: input with comments or non-ISO dates you can't change, JObject / dynamic -heavy code, existing TypeNameHandling payloads, or dictionaries keyed by custom types. Most migration bugs come from different defaults, not missing features. Below is every difference I hit, with the exact exception messages from real runs.

HttpClient in .NET 10: IHttpClientFactory, Timeouts, Retries

Last updated: October 8, 2026 · Tested with .NET 10 (SDK 10.0.401, runtime 10.0.12), Microsoft.Extensions.Http.Resilience 10.10.0 (Polly.Core 8.4.2), Windows 11 Short answer: don't create a new HttpClient() per request. Get clients from IHttpClientFactory ( AddHttpClient , named or typed), or keep one static HttpClient on a long-lived SocketsHttpHandler with PooledConnectionLifetime set so DNS changes are picked up. For retries and timeouts add AddStandardResilienceHandler() from Microsoft.Extensions.Http.Resilience and let it own the timeouts. Below is what I measured against a local Kestrel test server: 2,000 sockets left in TIME_WAIT by the per-request pattern, the exact timeout exceptions, real retry logs, a measured Retry-After delay, and one surprise: the standard handler silently replaces your HttpClient.Timeout .

CSharpier vs dotnet format: C# Code Formatting on .NET 10

Last updated: October 5, 2026 · Tested with CSharpier 1.3.0 (dotnet tool and CSharpier.MSBuild), dotnet format from SDK 10.0.401, Windows 11 Short answer: CSharpier is an opinionated formatter: it rewraps long lines, sorts usings and gives every file the same layout, with almost nothing to configure. dotnet format ships with the SDK and fixes spacing, indentation and code-style rules from .editorconfig , but it never wraps a long line. Use CSharpier for layout and keep dotnet format style and analyzers for code rules. Don't run dotnet format whitespace on top of CSharpier: with a common .editorconfig setting the two tools undo each other and your CI check fails either way. Below are the real before/after files, timings on 3,050 files, and the setup that worked.

Compile C# at Runtime in .NET: CSharpCodeProvider to Roslyn

Last updated: October 5, 2026 · Tested with .NET 10 (SDK 10.0.401, runtime 10.0.12), Microsoft.CodeAnalysis.CSharp 5.9.0, System.CodeDom 10.0.12, Windows 11 Short answer: CSharpCodeProvider cannot compile code on .NET Core or .NET 5+. Without the System.CodeDom package the code doesn't build (CS1069), and with it, CompileAssemblyFromSource throws PlatformNotSupportedException at runtime. The replacement is Roslyn: add Microsoft.CodeAnalysis.CSharp , build a CSharpCompilation , Emit it to a MemoryStream and load the bytes. Below is the working version on .NET 10, plus the four things that broke when I tried it: the reference list from most older examples fails with CS0012, compiled assemblies never unload unless you use a collectible AssemblyLoadContext , single-file publishing breaks references, and a CancellationToken does not stop code that never returns.

C# for Unity: Beginner to Advanced Guide (2026)

Learn C# for Unity from beginner to advanced in 2026 — MonoBehaviour lifecycle, coroutines, async, performance and DOTS. Start building games today. If you want to build games in 2026, learning C# for Unity is still the single highest-leverage skill you can pick up. Unity ships with C# as its only first-class scripting language, and the version of C# you write inside the editor today is a modern, fast, fully-featured language — not the cut-down dialect people remember from a decade ago. This guide walks you from your very first MonoBehaviour to advanced topics like the Job System, object pooling and allocation-free game loops, with runnable code you can paste straight into a project. Why C# for Unity Is Different From "Normal" C# Everything you know about .NET still applies — LINQ, generics, async , pattern matching, records. But Unity adds a layer on top that trips up almost every newcomer, and understanding it early will save you weeks. You don't own the ...

API Security Best Practices 2026: Secure REST APIs in C#

Learn API security best practices for 2026 with runnable C# and ASP.NET Core examples — JWT, rate limiting, BOLA fixes. Start hardening your REST API today. If you ship a REST API in 2026, you are running a public attack surface. Attackers no longer bother with your UI — they read your OpenAPI document, enumerate your endpoints, and hammer them directly. This guide covers the API security best practices that actually matter today, with runnable C# and ASP.NET Core examples you can drop into a real project. We will focus on the failures that show up in genuine breach reports: broken object-level authorization, weak token validation, missing rate limits, and secrets sitting in source control. Every example targets ASP.NET Core on .NET 8 or later, and each one explains why the control exists — because a security rule you do not understand is a security rule you will disable the first time it breaks a deployment. Why REST API Security Fails: The OWASP API Security Top 10 The OW...

Serilog .NET Tutorial: Structured Logging Best Practices

Learn Serilog structured logging in .NET with runnable C# examples, sinks, enrichers, and production best practices. Start logging smarter today. If you have ever opened a 400 MB text log file at 2 a.m. trying to figure out why one customer's checkout failed, you already understand why Serilog .NET exists. Traditional logging writes sentences. Serilog writes data. That single difference — structured logging instead of string concatenation — is what turns your logs from a wall of text into a queryable database of everything your application did in production. In this tutorial you will learn how to set up Serilog in a .NET 8/9 application, configure sinks and enrichers, use scopes and correlation IDs, and apply the production best practices that separate a hobby project from a system you can actually operate. Every example is runnable. What Is Structured Logging (and Why String Logs Fail) Consider the classic approach: // The old way — information is destroyed at write ti...

Azure Cosmos DB C# Tutorial: Complete Guide (2026)

Learn Azure Cosmos DB with C# in this step-by-step tutorial. Master partition keys, RUs, LINQ queries, and .NET SDK best practices. Start building today! If you have ever watched a SQL Server database buckle under traffic from three continents at once, you already understand why Azure Cosmos DB exists. Working with Azure Cosmos DB C# applications gives you a globally distributed, multi-model database with single-digit millisecond reads, 99.999% availability, and elastic scale — all reachable through a first-class .NET SDK. This tutorial walks you through everything from your first container to advanced patterns like bulk ingestion, optimistic concurrency, and change feed processing. We will use the Microsoft.Azure.Cosmos v3 SDK on .NET 8/9, and every example is runnable. More importantly, we will explain why each decision matters — because in Cosmos DB, an innocent-looking design choice can multiply your monthly bill by ten. What Is Azure Cosmos DB and Why Should C# Develop...

Git Best Practices for .NET Teams: Branching & PRs

Learn Git best practices for .NET teams — branching strategies, clean commits, and pull request reviews that scale. Start shipping safer C# code today. Most .NET teams don't lose time to hard algorithms. They lose it to a 4,000-line pull request nobody wants to review, a develop branch that hasn't been merged in three weeks, and a merge conflict in a .csproj file that silently drops a package reference. Adopting solid git best practices fixes more delivery problems than any refactor, because it changes how your team integrates work rather than how one developer writes it. This guide covers the Git workflow decisions that matter specifically for C# and .NET teams: which branching strategy to pick, how to write commits that survive a production incident, how to keep pull requests reviewable, and the .NET-specific pitfalls (solution files, generated code, secrets in appsettings.json ) that generic Git tutorials never mention. Why Git Best Practices Matter More in .NET C...

GitHub Actions CI/CD for .NET: Build, Test & Deploy Guide

Learn GitHub Actions CI/CD for .NET with a complete YAML workflow to build, test and deploy your app to Azure. Copy the pipeline and ship today. If you are still clicking "Publish" from Visual Studio to get your API into production, you are one tired Friday away from an outage. GitHub Actions .NET pipelines solve that problem: every push builds your solution, runs your tests, and — when the tests pass — ships the artifact to Azure, AWS, or your own server, without a human touching a button. In this tutorial you will build a complete GitHub Actions CI/CD workflow for a .NET 10 application from an empty YAML file to a production deployment with environment approvals, and you will understand why each block exists rather than just copying it. Everything below is runnable. You will need a GitHub repository, a .NET solution with at least one test project, and (for the deployment half) an Azure App Service or any host that accepts a zip deploy. Why GitHub Actions for a .NET ...