Disabling HSTS for localhost on Chromium-based browsers

 
 
  • Gérald Barré
 
Http Strict Transport Security (HSTS) is a security mecanism that instruct the browser to automatically redirect http requests to https before sending a request to the server. When you are developing a web application, you should disable HSTS for localhost. This is because enabling HSTS on localhost has implication on other applications. For instance, some applications start a local web server and open a… [read more]

How to detect Globalization-Invariant mode in .NET

 
 
  • Gérald Barré
Some libraries doesn't work when the application is running using Globalization-Invariant mode. This mode disabled all globalization features and force the use of the Invariant culture. This mode is useful for applications that don't need globalization features and want to reduce the application size. If your library doesn't support this mode, you may want to report a good error message to the user. So,… [read more]

How to Control Visual Studio from an external application

 
 
  • Gérald Barré
There are multiple use-cases where you need to get information from running instances of Visual Studio. For instance, if you create a git client, you may suggest the repositories that correspond to the opened solution, or you want know if a file is not saved in the editor and show a warning. Maybe you need to close the current solution and open a new one. All of this is possible with Visual Studio as it… [read more]

Reading Windows Application Manifest of an exe in .NET

 
 
  • Gérald Barré
The application manifest file is a compatibility feature that allows Windows to run older applications on newer versions of Windows. It contains information such as the supported versions of Windows, if it should run as administrator, if it supports long paths, etc. This file is stored as an embedded resource in the exe file. .NET doesn't provide any built-in way to read this file. You need to use interop… [read more]

Detecting Dark and Light themes in a WPF application

 
 
  • Gérald Barré
If an application support both light and dark themes, it is important to detect the current system theme and update the application accordingly. In this post, I describe how to detect if a WPF application should use the light or dark theme. Method 1: Using the registry and the Windows message loop Windows stores the current theme in the registry. The following code reads the current theme from the… [read more]

Investigating a crash in Enumerable.LastOrDefault with a custom collection

 
 
  • Gérald Barré
Have you ever seen the following thread-safety remark on some concurrent collections? Thread-Safety remark for ConcurrentBag In this post I'll explain what it means. Indeed, we got a crash in an application when using Enumerable.LastOrDefault on a custom collection that has the same thread-safety remark. Here's the call stack of the crash: System.ArgumentOutOfRangeException: Specified argument was out of… [read more]

Listing all available ETW events in a .NET application

 
 
  • Gérald Barré
When tracing an application, it can be useful to know which ETW events are available. .NET exposes many events to trace an application as shown in some previous posts (Getting telemetry data from inside or outside a .NET application, or Avoid DNS issues with HttpClient in .NET). It's hard to know which events are available and which ones are actually sent by the application. In this post, I describe how… [read more]

Handling CancelKeyPress using a CancellationToken

 
 
  • Gérald Barré
You sometimes need to detect when a console application is closing to perform some cleanup. Console.CancelKeyPress allows to register a callback when a use press Ctrl+C or Ctrl+Break. This event also allows to prevent the application from closing, so you can take a few seconds to perform the cleanup before actually terminating the application. The idea of this post is to use Console.CancelKeyPress to… [read more]