Understanding When Type.FullName Returns Null in .NET

 
 
  • Gérald Barré
A colleague recently asked me an interesting question: "Why does Type.FullName return null in certain situations?" Indeed, the method signature is public abstract string? FullName { get; } This behavior might seem unexpected, but there are specific scenarios where the .NET runtime cannot generate a valid full name for a type. Here are the two main cases where Type.FullName returns null: Generic Types with… [read more]

How to Find an Available Network Port for a server in .NET

 
 
  • Gérald Barré
When working with network programming in .NET, you might need to find an available port on your system. This is particularly useful when creating server applications, running tests, or developing tools that need to bind to a network port without conflicts. Here's a simple way to get an available port using the Socket class: Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,… [read more]

Using Git insteadOf to Automatically Replace HTTPS URLs with SSH

 
 
  • Gérald Barré
When working with Git repositories, you often encounter URLs in HTTPS format, especially when cloning from GitHub, GitLab, or other hosting services. However, if you prefer using SSH for authentication (which is often more convenient with key-based auth), manually changing URLs can be tedious. Also, it can be even harder when dealing with submodules. Git's insteadOf configuration option provides an… [read more]

Batch migrate .sln files to .slnx format across repositories

 
 
  • Gérald Barré
.NET has introduced a new solution file format called .slnx that offers significant improvements over the traditional .sln format: Better readability: XML-based structure that's human-readable Simplified merging: Reduces merge conflicts compared to the legacy format Easier parsing: Can be manipulated programmatically outside IDEs (for .NET devs, you can use microsoft/vs-solutionpersistence) To start using… [read more]

Open Windows Explorer to a Specific Path in C#

 
 
  • Gérald Barré
Sometimes, you need to open Windows Explorer to a specific folder from your C# application. This can be useful for improving user experience, providing quick access to files, or integrating with other tools. In this post, I'll show you how to achieve this using the Windows Shell API via the Microsoft.Windows.CsWin32 package, and discuss an alternative using Meziantou.Framework.FullPath. To use Windows… [read more]

Using Multiple Loopback Addresses for Socket Binding

 
 
  • Gérald Barré
127.0.0.1 is a reserved IP address that refers to the local machine. It is commonly used for testing and development purposes, allowing applications to communicate with themselves without needing an external network connection. But, the full range of loopback addresses is from 127.0.0.0 to 127.255.255.255 (127.0.0.0/8), which means you can use other addresses in this range for similar purposes. The… [read more]

Git Worktree: Managing Multiple Working Directories

 
 
  • Gérald Barré
Git worktree is a powerful feature that allows you to have multiple working directories associated with a single repository. Instead of switching branches and potentially losing uncommitted work, you can check out different branches in separate directories simultaneously without recloning the repository. Git worktree creates additional working trees linked to the same repository. Each worktree can have a… [read more]

Accessing Windows Known Folders in C# with SHGetKnownFolderPath

 
 
  • Gérald Barré
Windows has a list of well-known folders such as Documents, Pictures, Music, etc. You can access most of these folders using the Environment.GetFolderPath method in C#. Here's an example: Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); However, this list is limited to the folders defined in the Environment.SpecialFolder enumeration. If you need to access other well-known folders, such as… [read more]

Reduce boilerplate and maintain project consistency

 
 
  • Gérald Barré
Before reading: If you work in a small company with only one or two projects, this post may not be relevant for you. I've worked for companies of various sizes, from small startups to organizations with thousands of developers. While small companies typically have one or two projects, large companies can have hundreds or thousands of repositories. As organizations grow, keeping all projects aligned and… [read more]