RSSAmplifier

Blog

Meziantou's blog

Blog about Microsoft technologies (.NET, ASP.NET Core, Blazor, EF Core, WPF, TypeScript, etc.)

meziantou.netRSS feed ↗10 posts

Latest posts

Snapshot testing in .NET with Meziantou.Framework.SnapshotTesting

Snapshot testing is a technique where the output of a function or component is serialized and saved to disk the first time the test runs. On every subsequent run, the library re-serializes the output and compares it against the saved file. If they differ, the test fails. Meziantou.Framework.SnapshotTesting is a .NET library that makes snapshot testing straightforward. It handles serialization,…

Adding a Clone method to a C# record

Adding a Clone method to a C# record When using records, creating a copy with with is concise: var sample = new Sample("meziantou"); _ = sample with { }; public record Sample(string Value); This works well, but sample with { } is not always obvious as a discoverable Clone API for consumers. Why public Sample Clone() is not allowed Records already have compiler-generated clone behavior used by…

Get a Unicode character name from a Rune in .NET

If you have a Rune and want its Unicode name (for example GRINNING FACE for 😀), there is no built-in API in .NET today. Here are two practical options: Use the ICU library available on the operating system Use the Meziantou.Framework.Unicode NuGet package Method 1: Use ICU from the OS ICU exposes u_charName, which returns the Unicode name for a code point. using System; using…

Enable SHA Pinning for GitHub Actions Across Personal Repositories

Pinning GitHub Actions to a full-length commit SHA is one of the simplest ways to reduce supply chain risk in your workflows. It ensures that a workflow keeps using the exact code you reviewed, instead of silently following a moving tag or branch. Tags are convenient, but they are mutable. A workflow that uses actions/checkout@v4 or a third-party action pinned to a tag can start running different…

Generate a Kiota client at build time from an ASP.NET Core OpenAPI file

In a previous post, I explained how to generate the OpenAPI document during the ASP.NET Core build and commit it to the repository. That gives you a versioned API contract that is easy to review in pull requests. In this post, let's go one step further: use that generated OpenAPI file as the input for Kiota, so your typed .NET client is also generated during build. The goal is simple: The server…

New lines are more than \r and \n

When we talk about new lines, most developers think about \r\n (Windows) and \n (Unix-like systems). That works most of the time, but it is not the full picture. Unicode and several regex engines recognize additional line break characters. If your application parses user input, logs, CSV-like content, or cross-platform data, this can matter more than you think. The line breaks you should know The…

New features and Roslyn analyzers for Meziantou.Framework.FullPath

A few years ago, I introduced , a library to ensure you always deal with full paths in your applications and provide common methods to manipulate them easily. Recently, I've added new features to the library, including new methods and a set of Roslyn analyzers to help you use the library correctly. The main idea of FullPath is to avoid bugs related to relative paths by forcing the use of absolute…

Blazor - How to set a base component for all Razor components

When building a Blazor application, you may want a custom base component for all your Razor components. This is useful for sharing common functionality like cancellation tokens, logging, or state management across all components. Instead of adding @inherits YourBaseComponent to every Razor file, you can use the _Imports.razor file to set it globally. Using _Imports.razor to set a default base…

Propagating OpenTelemetry context in .NET

When building distributed systems, maintaining observability across process boundaries is crucial for understanding the flow of requests through your application. OpenTelemetry provides a standard way to propagate tracing context, but implementing it correctly requires understanding several key concepts. This post explains how to propagate telemetry context in .NET applications, particularly when…

Disable HTTP caching by default in ASP.NET Core APIs

When building APIs with ASP.NET Core, it's crucial to explicitly control caching behavior. Unlike web pages where caching often improves user experience, API responses should not be cached by default unless you intentionally design them to be cacheable. Unintended caching can lead to serious issues, including stale data, security vulnerabilities, and hard-to-reproduce bugs. Understanding HTTP…