Zero-copy BinaryData creation from MemoryStream in .NET

 
 
  • Gérald Barré
When working with BinaryData and MemoryStream in .NET, you might need to convert stream data into a BinaryData instance. The typical approach using BinaryData.FromStream() involves copying the entire buffer, which can impact performance and increase memory allocations. However, there's a more efficient way to achieve this with zero memory copies. The problem with BinaryData.FromStream() The standard way… [read more]

Understanding and Managing Mark of the Web in .NET

 
 
  • Gérald Barré
What is Mark of the Web? Mark of the Web (MOTW) is a Windows security feature that protects users from potentially unsafe files downloaded from the internet. When you download a file, Windows automatically adds a special metadata tag indicating the file originated from an untrusted source and may contain harmful content. Windows components such as Microsoft Edge and Windows Explorer use MOTW to determine… [read more]

Resolving Overload Ambiguity with Collection Expressions

 
 
  • Gérald Barré
OverloadResolutionPriority allows you to specify which method overload should be preferred by the compiler when multiple overloads are applicable. This can be useful in scenarios where you have multiple methods with types that can be implicitly converted to each other, and you want to control which overload is chosen. I've found this feature particularly useful when having existing overloads that take… [read more]

Creating a custom MSBuild SDK to reduce boilerplate in .NET projects

 
 
  • Gérald Barré
This blog post is part of The C# Advent Calendar 2025, a series of 50 posts about C#. Be sure to check out the rest of the blog posts in the calendar! Over the years, I've relied on Meziantou.DotNet.CodingStandard, a NuGet package, to establish a consistent baseline across all my .NET projects. This approach includes style enforcement, essential analyzers, sensible build defaults, and additional tooling.… [read more]

Update Local Git Branches Without Switching

 
 
  • Gérald Barré
If you frequently need to work on multiple branches simultaneously, consider using Git Worktree to maintain separate working directories for each branch, eliminating IDE reloads entirely. When you need to switch to a branch that is not up to date with the remote branch, the typical workflow involves switching to that branch and pulling the latest changes. This process can be time-consuming and disruptive… [read more]

Optimize GUID creation performance in .NET applications

 
 
  • Gérald Barré
Many .NET projects use well-known GUIDs as identifiers for activities, interop scenarios, database keys, and other purposes. It's common to see code like new Guid("01234567-8901-2345-6789-012345678901") throughout applications. While this approach is readable and straightforward, it comes with a hidden performance cost that can impact application startup time. This is a micro-optimization that primarily… [read more]

C# 14 Extension Members: Enhancing Polyfill Libraries

 
 
  • Gérald Barré
C# has long supported extension methods, allowing developers to add new methods to existing types without modifying the original type. However, this capability was limited to instance methods. With C# 14, the language introduces extension members, significantly expanding what you can extend. You can now add extension properties and extension static methods to existing types. This enhancement is… [read more]

Using Git Conditional Includes for Multiple Configurations

 
 
  • Gérald Barré
When working across multiple Git repositories, you often need different configurations for each context. For example, you might use your personal email for open-source contributions and your work email for company projects. While you can configure Git globally or per repository, managing these settings manually becomes tedious and error-prone. Git's conditional includes feature solves this problem by… [read more]