Writing a .NET profiler in C# 

#547 – March 09, 2025

CPU profiler for .NET using Silhouette

Writing a .NET profiler in C# 
10 minutes by Kevin Gosse

In this guide Kevin demonstrates how to create a basic CPU profiler for .NET using Silhouette, a library that wraps profiling APIs. He shows how to set up a project with NativeAOT, implement stack walking functionality, track running threads, and resolve method names from instruction pointers. The example includes a complete implementation of a simple profiler that periodically captures and displays stack traces of all managed threads, written entirely in C# rather than the traditional C++ approach.

Deliver Data-Heavy Blazor Apps in Half the Time
sponsored by Progress Telerik

UI Library With 110+ Native Components for Building Modern and Feature-Rich Applications. Featuring the Fastest Blazor Grid, Charts, Scheduler, Editor, Dropdown list and many more. See demos here.

Implement Phone verification, 2FA using ASP.NET Core Identity
7 minutes by Damien Bod

In this article Damien demonstrates how to implement SMS verification and two-factor authentication (2FA) in ASP.NET Core Identity applications. It provides a detailed guide for integrating phone-based verification during user registration and login processes using ASP.NET Core Identity's extensibility features. While acknowledging that SMS is not the most secure authentication method, the article explains it can be useful for specific business cases like onboarding phone users or frontline workers.

Injecting Action Method Values from Configuration in ASP.NET Core
5 minutes by Ricardo Peres

In this post Ricardo presents how to create a custom model binding mechanism in ASP.NET Core to inject configuration values directly into action method parameters. He shows how to build a custom binding source, model binder provider, and model binder, along with an extension method for registration and a `FromConfiguration` attribute.

Creating an analyzer to detect infinite loops caused by ThreadAbortExceptions
12 minutes by Andrew Lock

Andrew explains a bug in .NET Framework where ThreadAbortException can cause infinite loops when a try-catch block is nested directly inside a while loop without manual re-throwing. This occurs because the runtime fails to automatically re-throw the exception as it normally should. Andrew describes a Roslyn Analyzer they created to detect this problematic pattern and provide a code fix that adds a manual "throw;" statement to prevent the infinite loop.

Mastering C# Design Patterns: Practical Examples of Singleton, Factory, and Observer
5 minutes by Leandro Veiga

In this article Leandro explores three essential design patterns in C# - Singleton, Factory, and Observer - and he provides practical examples and cases for each. He explains how these patterns solve common software challenges by offering reusable solutions that improve code maintainability and scalability.

And the most popular article from the last issue was:

 

newsletters