Latest

  1. Image: Andrew Lock

    Understanding Lazy thread safety modes

    Andrew Lock explains the thread-safety modes of .NET's Lazy type, available since .NET Framework 4.0 and .NET Core 1.0, focusing on how LazyThreadSafetyMode interacts with exceptions. The post uses the factory-method form, where object creation is deferred until the Value property is accessed, with code examples demonstrating each mode's behavior.

  2. Image: Andrew Lock

    An introduction to Compact Binary Object Representation (CBOR) in .NET

    A blog post introduces the Concise Binary Object Representation (CBOR) serialization format, explaining when and why to use it instead of formats such as JSON. It then demonstrates reading and writing CBOR in .NET using the System.Formats.Cbor package.

  3. Image: Andrew Lock

    Stripping extra dependencies in .NET NativeAOT apps using linker substitutions

    A Datadog engineer describes using linker method substitutions to strip unneeded dependencies from dd-dotnet, a NativeAOT-compiled command line tool shipped with the Datadog .NET SDK. Updating the ClrMD (Microsoft.Diagnostics.Runtime) package for upcoming .NET 11 support pulled in a web of dependencies the linker could not remove on its own. Substitutions enabled additional dead-code elimination and significantly reduced the final binary size.

  4. Image: Andrew Lock

    Experimental support for Device Bound Session Credentials (DBSC) in ASP.NET Core: Exploring the .NET 11 preview - Part 8

    Andrew Lock examines the experimental Device Bound Session Credentials support released for .NET 11 in the Microsoft.AspNetCore.Authentication.DeviceBoundSessions package. The eighth part of his .NET 11 preview series shows how to add it to an ASP.NET Core Identity application, its effect on browser-server requests, and implementation details. DBSC aims to counter cookie theft and session hijacking involving long-lived authentication cookies.

  5. Image: Andrew Lock

    Understanding Device Bound Session Credentials (DBSC)

    A blog post introduces Device Bound Session Credentials (DBSC), a protocol aimed at preventing session hijacking through stolen authentication cookies. It explains that session cookies act as bearer tokens, so anyone holding one can use it, even with protections such as same-site cookies. The post describes how the protocol works and what web applications need to do to support it.

  6. Image: Andrew Lock

    The pain of serializing unions and closed class hierarchies with System.Text.Json: Exploring the .NET 11 preview - Part 7

    The seventh part of a blog series on the .NET 11 preview tests how System.Text.Json handles the union types and closed class hierarchies being added in .NET 11 and C# 15. The author builds simple examples of each and attempts to serialize them, working through a series of errors. The post outlines differences between the two type hierarchies and sharp edges to watch for, and the author concludes the serialization could not be made to work.

  7. Image: Andrew Lock

    Finding the total number of processors on a machine with .NET

    Andrew Lock describes how to find the total number of processors on a host or VM in modern .NET, which lacks a direct API, using P/Invoke on some platforms and file parsing on Linux. Environment.ProcessorCount returns host logical processors on .NET Framework, is partly container-aware on .NET Core before 6, and from .NET Core 6 returns processors available to the process when affinity or containers apply.

  8. Image: Andrew Lock

    Automatic CSRF protection based on Fetch Metadata headers: Exploring the .NET 11 preview - Part 6

    ASP.NET Core in .NET 11 preview 6 adds Cross-Site Request Forgery protection based on Fetch Metadata HTTP headers instead of the traditional anti-CSRF tokens used in earlier .NET Core versions. The sixth part of a series on the .NET 11 preview explains CSRF attacks, the existing protections in ASP.NET Core and why the new approach is now possible. It then shows how the header-based protection works in practice.

  9. Image: Andrew Lock

    Understanding the Fetch Metadata HTTP headers: Sec-Fetch-Site and friends

    A blog post explains the Fetch Metadata HTTP request headers, including Sec-Fetch-Site, which browsers have sent for several years. It covers what each of the four headers means, when they are sent and how servers might use them. The Fetch Metadata Request Headers specification was first published in 2019, with the latest version in 2025, and gives servers context on whether a request is legitimate or maliciously triggered. A follow-up post covers how .NET 11 will use the headers for simpler CSRF protection.

  10. Image: Andrew Lock

    Improvements to reading Process outputs: Exploring the .NET 11 preview - Part 5

    The fifth part of a blog series on the .NET 11 preview examines improvements to the Process APIs, led by Adam Sitnik. The changes simplify common tasks such as running a process and reading its output, and add features such as fire-and-forget execution and killing child processes on parent exit. The post focuses on new ways to read child-process output that help avoid failures such as deadlocks, building on foundations from early .NET 11 previews.

  11. Image: Andrew Lock

    Closed class hierarchies: Exploring the .NET 11 preview - Part 4

    The fourth part of a series on the .NET 11 preview explores closed class hierarchies, available in .NET 11 preview 5. A closed class hierarchy can only be defined within a single assembly, and deriving from a closed class in another assembly produces a compilation error. The post shows how to declare one with the closed keyword, such as a closed Animal base class, and discusses why developers might use the feature.

  12. Image: Andrew Lock

    .NET (OK, C#) finally gets union types🎉: Exploring the .NET 11 preview - Part 2

    C# 15, shipping with .NET 11, adds union types, a long-requested feature common in functional languages and available in F#, TypeScript and Rust. A post in a series on the .NET 11 preview describes how the support works, how to use unions, how they are implemented, and how to build custom union types. It is based on .NET 11 preview 4, and behavior may change before the final release.

  13. Image: Andrew Lock

    Running background tasks in Blazor with Web Workers: Exploring the .NET 11 preview - Part 1

    The first post in a series exploring the .NET 11 preview covers the new Web Worker template in the .NET 11 SDK for Blazor. It explains how to add the template to an existing app, what the code does behind the scenes, and how to run CPU-intensive work such as image processing without blocking the UI. The walkthrough is based on .NET 11 preview 3, and features may change before the final release.

  14. Image: Andrew Lock

    New features in Git 2.54: easier rebasing, hooks, and statistics

    Git 2.54 adds a new git history command for simple rebases, hooks that can be defined in config, and statistics about a repository. The git history command supports two operations: reword, which changes the message of a specific commit, and split, which divides a specific commit in two. The command targets users who find full interactive rebasing with git rebase -i daunting or error-prone.

  15. Image: Andrew Lock

    Removing byte[] allocations in .NET Framework using ReadOnlySpan

    Andrew Lock describes a technique for removing byte[] allocations using ReadOnlySpan that works on any .NET version, including .NET Framework. The post covers the required C# code changes, how the compiler implements the optimization behind the scenes, and caveats and sharp edges developers should watch for. It applies an approach familiar from modern .NET performance work to older runtimes.

  16. Image: Andrew Lock

    Running AI agents with customized templates using docker sandbox

    Andrew Lock shows how to create custom templates for Docker's sbx sandbox tool so AI agent sandboxes start with additional tools. The guide covers extending the default template and starting from a different Docker image before layering on sandbox tooling. Docker sandboxes run in isolated microVMs, offering a safer alternative to bypass-permissions mode, though Lock notes .NET builds of his own projects hung indefinitely inside them.

  17. Image: Andrew Lock

    Running AI agents safely in a microVM using docker sandbox

    A developer describes running coding agents such as Claude Code locally in "YOLO" or dangerous mode while staying safe by isolating them in a microVM with Docker Sandboxes. The approach targets the constant tool-call permission prompts that agents raise for commands like grep and sed. The author notes ethical and environmental concerns about AI while arguing that working with coding agents is becoming a job requirement.

  18. Image: Andrew Lock

    Configuring contextual options with Microsoft.Extensions.Options.Contextual

    A blog post examines the little-known Microsoft.Extensions.Options.Contextual package from the dotnet repositories, which provides APIs for dynamically configuring options based on a given context. The author found no other first-party .NET libraries using it. The post walks through installation and configuration with a weather forecast example and assesses whether developers should adopt it.

  19. Image: Andrew Lock

    Splitting the NetEscapades.EnumGenerators packages: the road to a stable release

    Andrew Lock has restructured his NetEscapades.EnumGenerators source generator NuGet package, which adds fast methods for working with enums, into three separate packages. The right package depends on the user's scenario. The project, built on the incremental generator support introduced in .NET 6, is heading toward a stable 1.0.0 release, and users are asked to raise issues with the new structure before it is finalized.