xUnit vs NUnit vs MSTest: Which C# Test Framework to Pick

xUnit vs NUnit vs MSTest attribute names side by side: Fact, Test, TestMethod, InlineData, TestCase, DataRow, setup, cleanup and assert methods

Say you’re testing the shipping fee for an online store in Columbus, Ohio: $8.95 under $75, free above it, plus $15 for Alaska and Hawaii. I wrote the same tests in xUnit, NUnit and MSTest, and all three caught the same Hawaii bug. My verdict on xunit vs nunit vs mstest: use xUnit for a … Read more >>

HttpClient Timeout in C#: Default Value and How to Change It

HttpClient timeout card: the default Timeout 00:01:40 changed to 5 seconds, ending in TaskCanceledException after 5.0 seconds

The mistake I see most with a C# HttpClient timeout is expecting a hung API call to fail fast. It won’t: the default Timeout is 100 seconds, and my stuck request on .NET 10 gave up after a full 100 seconds with a TaskCanceledException. The fix is one line, set before the first request: Every … Read more >>

Add a Bearer Token to HttpClient in C# (Header, Handler and Refresh)

C# code that calls an API without an Authorization header and gets 401 Unauthorized, then sets a Bearer token with AuthenticationHeaderValue and gets 200 OK

Your API call keeps coming back 401 Unauthorized, and the token is sitting right there in a variable. HttpClient just isn’t sending it. Quick answer: to send a C# HttpClient bearer token, set the Authorization header to an AuthenticationHeaderValue with the “Bearer” scheme: We tested it against a local .NET 10 API that returns real … Read more >>

HttpClient vs IHttpClientFactory in C#: Avoid Socket Exhaustion

C# code that sends 100 requests with new HttpClient per call and with one shared HttpClient, output showing 100 versus 0 sockets in TIME_WAIT

Use IHttpClientFactory when your app has dependency injection, and one shared HttpClient with PooledConnectionLifetime when it doesn’t. That’s my rule for C# HttpClient vs HttpClientFactory. The one wrong answer is new HttpClient() for every request. I sent 100 requests to a local API on .NET 10. A new client per call opened 100 connections and … Read more >>

System.Text.Json vs Newtonsoft.Json: Which Should You Use in 2026?

System.Text.Json vs Newtonsoft.Json benchmark table on .NET 10: serializing 500 orders took 611.5 us with System.Text.Json and 908.6 us with Newtonsoft.Json

If you’re choosing a JSON library for a new project, use the built-in serializer for anything on .NET 8 or later: System.Text.Json. Keep Newtonsoft.Json when code depends on its loose parsing, TypeNameHandling or JSONPath. That’s my verdict on System.Text.Json vs Newtonsoft.Json in 2026. I ran both on the same 500 US orders with BenchmarkDotNet 0.15.8. … Read more >>

JavaScript Interop in Blazor: Call JS from C# and C# from JS

Blazor JavaScript interop featured card: the C# call InvokeAsync formatUsd 18.40 goes through Checkout.razor.js and comes back as $18.40

Blazor JavaScript interop runs both ways. From C#, inject IJSRuntime and await InvokeVoidAsync (no result) or InvokeAsync<T> (a result). From JavaScript, call a C# method marked [JSInvokable] with DotNet.invokeMethodAsync. The catch is timing: there’s no browser during prerendering, so JS calls belong in OnAfterRenderAsync. I ran every pattern below on .NET 10, in one checkout … Read more >>

BackgroundService vs IHostedService in ASP.NET Core (.NET 10)

BackgroundService vs IHostedService in ASP.NET Core: IHostedService blocked startup for 2.02 s and BackgroundService for 0.00 s on .NET 10

Use BackgroundService for work that runs as long as the app does, like a sync loop, and IHostedService only when you need exact control over start and stop. That’s the rule for BackgroundService vs IHostedService: one is built on the other. I timed both on .NET 10 with 2 seconds of blocking startup work. IHostedService … Read more >>