Skip to main content

Posts

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. Install CSharpier (1.x Commands) Install it as a local tool so everyone on the team and the build server use the same version: dotnet new tool-manifest dotnet tool install csharpier dotnet csharpier format . do...

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. The Error: CSharpCodeProvider on .NET Core and .NET 10 This is the classic .NET Framework way to compile C# at r...

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...