C# Digest


A free weekly newsletter has been designed for .NET developers, aiming to assist in their continuous learning and keeping them updated with the latest advancements in technology.



#1043 March 13, 2024
Using Unix domain sockets with ASP.NET Core and HttpClient

I describe Unix domain sockets, what they are, the scenarios where they're useful, how to use them with ASP.NET Core, and how to call a UDS ASP.NET Core app using HttpClient.

Docker Init for ASP.NET Core Compared to VS or VS Code Extensions

Docker began introducing a new CLI command, docker init, allowing us to easily build stake-in-the-ground Dockerfile, docker-compose and .dockerignore files for a project.

How to Use Polly In C#: Easily Handle Faults And Retries

This article explores three different use cases of Polly, covering fault handling, basic retries, and advanced retry patterns like circuit breakers. It highlights the versatility and resilience Polly offers in software development.

Boundaries are explicit

This problem isn't isolated to WCF or SOAP. Network calls are slow and unreliable. Perhaps you're connecting to a system on the other side of the Earth. Perhaps the system is unavailable.

Performance test your ASP.NET Core application using NBomber

NBomber is a load-testing framework for Pull and Push scenarios, designed to test any system regardless of a protocol (HTTP/WebSockets/AMQP, etc) or a semantic model (Pull/Push).

#1042 March 07, 2024
How to Call SignalR Hub from Controller in ASP.NET Core

If you are unfamiliar with setting up SignalR in your server and/or client application, check out our article for more information.

Understanding Middleware and Filters in .NET Core

In .NET Core Web Application development, it’s important to know the difference between middleware and filters. They both help manage important parts of your app, but they work in different ways.

Blazor Basics: Validating Form Data with Blazor

In this article, we will learn how to validate user input and provide visual feedback in case of an error.

ConfigureAwaitOptions in .NET 8

In this post I want you to show how this method got some enhancements in .NET 8. But before I do that let's first recap the original behavior (just in case you forgot).

Using ChatGPT and GitHub Copilot to Generate the XAML for your Windows application

In this post I’m going to experiment using ChatGPT and Copilot to help generate the XAML for pages in a Windows application. Since we’ll be using WinUI and the Windows App SDK, the application can be extended to support other platforms via the Uno Platform.

#1041 February 29, 2024
.NET February 2024 Updates – .NET 8.0.2, 7.0.16, .NET 6.0.27

These updates contain security and non-security improvements. Your app may be vulnerable if you have not deployed a recent .NET update.

My Top 10 NEW Visual Studio Features of 2023 for .NET Developers

Visual Studio 2022 saw an abundance of incredible features released in 2023, which gave .NET developers a host of new tools to enhance their productivity.

Using Unix domain sockets with ASP.NET Core and HttpClient

A Unix domain socket (UDS) is an endpoint for communication between processes on the same host.

The FAST and the Fluent: A Blazor story

It almost seems like a title from the popular movie series, but we are not movie creation material (yet).

Azure Functions Extensibility - Runtime Scaling

The Azure Functions scaling model (as one can expect) has evolved over the years. The first model is incremental scaling handled by the scale controller (a dedicated Azure Functions component).

#1040 February 22, 2024
Feature Flags 101: A Guide for ASP.NET Core Developers

Feature Flags are a technique that allows you to control the visibility and functionality of features in your software without changing the code. They enable you to experiment with new features, perform gradual rollouts, and revert changes quickly if needed.

Visual Studio Presentation Mode

I recently discovered that Visual Studio has a Presentation Mode. Presentation Mode is a feature that lets you open an instance of Visual Studio that looks like a fresh install, without any customizations, extensions, or settings synchronization.

How to Map SQL Results To Any Object Using EF Core 8

Before the EF Core 8 release, all entities that were to be queried from a DbContext had to be registered within the implementation.

Property based testing in C# CsCheck

CsCheck offers no specific integration but can be used with any testing framework(XUnit, NUnit, MSTest, …).

Share a private key without using passwords

If you follow security best practices, you are not re-using the same password for multiple purposes.

#1039 February 14, 2024
My Top 10 NEW Visual Studio Features of 2023 for .NET Developers

Visual Studio 2022 saw an abundance of incredible features released in 2023, which gave .NET developers a host of new tools to enhance their productivity.

Secure an ASP.NET Core Blazot Web App using Microsoft Entra ID

This article shows how to implement an ASP.NET Core Blazor Web application using Microsoft Entra ID for authentication. Microsoft.Identity.Web is used to implement the Microsoft Entra ID OpenID Connect client.

8 ways to set the URLs for an ASP.NET Core app

By default, without additional configuration in .NET 8, ASP.NET Core apps listen on the URL http://localhost:5000.

Resilience and chaos engineering

This article introduces the concept of resilience and chaos engineering in .NET applications using the Polly library, highlighting new features that enable chaos engineering.

Creating an HttpClient that uses DNS over Https

DNS is a key component of the Internet. It's used to translate a domain name to an IP address.

#1038 February 07, 2024
ASP.NET Core Basics: Data Structures—Part 1

ASP.NET Core development relies on manipulating, storing and retrieving data. A solid understanding of data structures allows developers to design and implement web applications that can handle large volumes of data and quickly respond to requests, scaling the applications efficiently.

NoSQL vs SQL: Demystifying NoSQL Databases

In recent years, there’s been increasing amounts of discussion about NoSQL databases. One of the big reason for this is that the massive, Internet scale websites like Facebook, Twitter, Netflix, and many others rely on NoSQL databases heavily.

Embracing Functional Programming in C#

Throughout this exploration, we will clarify how functional programming can enhance code readability, efficiency, and unit testing, and we'll discuss how it can be applied in contemporary C# applications.

Why is Simple Code So Often Bad?

I had to write a custom hash map context (what Zig calls the eql and hash functions) which led to my last couple blog posts exploring Zig's hash maps in more details.

AutoMapper 13.0 Released

Probably the biggest change with this release is folding in Microsoft.Extensions.DependencyInjection support directly.

#1037 February 01, 2024
C# Tip: ObservableCollection - a data type to intercept changes to the collection

Imagine you need a way to raise events whenever an item is added or removed from a collection.

.NET Tasks, List's ForEach, and Problems

For those unaware, the List type has a ForEach method, which allows the user to pass an Action.

.NET 8–Refresh memory limit

With more and more workloads running in the cloud, optimizing the resource consumption becomes an important feature of every application.

Persisting data volumes with .NET Aspire

.NET Aspire is awesome for this, as you can setup a developer inner loop super simply with the components that ship, and the nice thing about this is that locally PostgreSQL is run in a Docker container and Azure Storage uses the Azurite storage emulator (which also happens to run in a container).

Log Request Headers Middleware for ASP.NET Core

Recently I ran into a weird problem with how Visual Studio was sending API requests and I really wanted to see exactly what headers were being sent to my ASP.NET Core app. So I wrote this simple bit of middleware to do the job.

#1036 January 24, 2024
.NET Blazor Hybrid – Windows Desktop Templates

Windows Forms and WPF are proven solid frameworks for creating high-performance Windows desktop client applications.

Interceptors – Using C# 12 in Rider and ReSharpera>

In this part, we will take a closer look at interceptors. Interceptors are an experimental feature available in preview mode in C# 12.

SerilogTracing

Traces are amazing for analyzing performance and for describing complex operations that flow across multiple systems.

A Range kata implementation in C#

This article is an instalment in a short series of articles on the Range kata. In the previous article I made a pass at the kata in F#, using property-based testing with Hedgehog to generate test data.

Visual Studio productivity features in 2023

Over the last year, we’ve invested heavily in new capabilities to help Visual Studio developers code more easily. Let’s look back on some of the additions that aim to make your coding experience more productive.

#1035 January 17, 2024
Some Stream.Read Guidelines

The Read method returns an integer that indicates how many bytes were actually read from the stream.

What is a hard error, and what makes it harder than an easy error?

Occasionally, you may see a reference in Windows to “hard errors”, such as in this article that shows how to configure an unattended system so that it auto-answers hard error dialogs.

Migrate ASP.Net Core Blazor Server to Blazor Web

This article shows how to migrate a Blazor server application to a Blazor Web application. The migration used the ASP.NET Core migration documentation, but this was not complete and a few extra steps were required.

.NET January 2024 Updates – .NET 8.0.1, 7.0.15, .NET 6.0.26

These updates contain security and non-security improvements. Your app may be vulnerable if you have not deployed a recent .NET update.

Deserialize a Serialized Nested Type Within a JSON Object

If you are using a queue or event bus, that service will have its own message or event type.

#1034 January 10, 2024
The One Billion Row Challenge

The One Billion Row Challenge is a fun exploration of how far modern .NET can be pushed for aggregating one billion rows from a text file.

Securing .NET/ASP.NET Core Apps with Azure Key Vault Middleware

Securing secrets in a .NET/ASP.NET Core application using Azure Key Vault is crucial for protecting sensitive information like API keys, connection strings, and other configurations.

.NET 8– System.Text.Json serializer error

I really like the System.Text.Json source generator as a way to optimize your API performance by reducing the serialization/deserialization cost.

Never delete tests

Ok, not never, but only delete them when they really serve no value and the codebase is improved by their removal.

The first possible new feature of C# 13: Params collection

Only one month after the big release of .NET 8, the dotnet team is already working on the next iteration: .NET 9. With that also comes new language features. The first one is about to be merged into the main development branch: Params Collections.

#1033 December 21, 2023
Snapshot log tests in .NET

Writing tests is important. The easier it is to write tests, the more likely they'll be written. I've long loved snapshot testing for this reason.

Functional Programming with C# Scan and FindIndex

So What's a Scan? It's actually going to take me a whhile to explain, but only a few lines of code to implement. It's similar to the C# Aggregate function (known as a "Fold" in FP parlance).

All purpose object updater

In my day job, we had a need to test a object for some condition, and if true, make some change to the object. For example, if in an order record, a credit card number is given, then the PayementType property must be set to CreditCard.

Blazor’s History and Full-stack Web UI

Blazor is a web framework that allows developers to build interactive web applications using .NET instead of JavaScript.

5 Serilog Best Practices For Better Structured Logging

Serilog supports many logging destinations called Sinks. The log destinations range from console and file sinks to managed logging services such as Application Insights.

#1032 December 13, 2023
Captcha component for Blazor

Jinget Blazor components are becoming open source. Jinget Blazor contains numerous useful components such as Captcha, Jalali datepicker, Jalali date range picker, table etc. In this article, configuring and using Captcha component has been described.

MAUI App Accelerator v1.4

Consider this a low-key announcement that version 1.4 of MAUI App Accelerator is now available in the Visual Studio marketplace.

Dealing with Zip Files in C#

In this post, I’ll cover some of the things that you can do with the System.IO.Compression namespace. We’ll discuss how you can use this namespace to manipulate zip files.

Festive Tech Calender - Building a Word Search in C#

Earlier this year, I created a project to build PDF word searches using C#. I was surprised to find although code existed in other languages, there were no open source solutions for making word searches in C#, so I set about creating my own project.

Hardware Intrinsics in .NET 8

.NET has a long history of providing access to additional hardware functionality via APIs that are intrinsically understood by the JIT compiler.

#1031 December 07, 2023
Scroll to expand document tabs

When you have lots of tabs open in Visual Studio, your horizontal screen resolution determines how many fit in the document tab well. The remaining document tabs are hidden unless you configure Visual Studio to display tabs in multiple rows.

Dissecting C# Ranges

We can see that the caret is the indicator to the compiler whether or not the fromEnd property on the Index is true.

How to Debug LINQ queries in C#

LINQ is one of my favorite features in C#. It just makes the code look nicer. Instead of tedious foreach loops, we got a neat functional syntax that’s easy to write and understand. Well, at least if we’re using the method syntax flavor of LINQ.

Upgrading to .NET 8

At VS Live in Orlando this week there were a number of people who had questions about upgrading to .NET 8; mostly from .NET Framework 4.5 or similar versions that are no longer supported.

Lo-Fi Service Discovery in .NET8

The vast majority of systems that you build will inevitably call a HTTP API at some point.

#1030 November 30, 2023
Tips & Tricks: Delaying AWS Service configuration when using .NET Dependency Injection

The AWSSDK.Extensions.NETCore.Setup package provides extensions for enabling AWS Service Client creation to work with native .NET Dependency Injection. Bindings for one or more services can be registered via the included AddAWSService method and a shared configuration can be added and customized via the AddDefaultAWSOptions method.

Behind [LogProperties] and the new telemetry logging source generator

In this post I take a look at an apparently simple enhancement to logging introduced along with .NET 8: the [LogProperties] attribute. This attribute can make it easier to log additional state in your log messages as you'll see later. While looking into the specifics of how this new attribute works, I discovered bigger changes to the logging source generator.

Preprocessor Directives in C#: Guide to Become a Pro

Analyze, tweak, control, and elevate your C# code using the power of preprocessor directives. Keep reading to unravel the tricks, tips, and benefits of using them effectively.

Building resilient cloud services with .NET 8

Building resilient apps is a fundamental requirement for cloud development. With .NET 8, we’ve made substantial advancements to simplify the integration of resilience into your applications. We’re excited to introduce the Microsoft.Extensions.Http.Resilience and Microsoft.Extensions.Resilience packages to the .NET ecosystem. These new libraries are based on the Polly library, a widely recognized open-source project.

Prime Numbers in C#: A Detailed Guide

Now, who doesn’t love a little magic trick? But what if I told you that the magic lies within your computer? Yes, that’s right! We’re about to embark on an exciting journey that fuses math and programming. Buckle up as we dive deep into prime numbers in C#.

#1029 November 16, 2023
ConfigureAwait in .NET 8

Originally, the community recommended using ConfigureAwait(false) everywhere you could, unless you needed the context.

Automating MEMORY PROFILING with the JETBRAINS DOTMEMORY PROFILER API

In this post, I want to demonstrate a really handy, but somewhat underutilised feature, to automate the collection of snapshots in a repeatable way. I use these steps quite often during local development.

Introducing .NET Aspire: Simplifying Cloud-Native Development with .NET 8

For several releases now we’ve been making progress on one of our ongoing aspirational goals. Making .NET one of the most productive platforms on the planet for building cloud-native applications.

Where fetch data in your Blazor components

When you build a single page in Razor pages (or view in MVC), it’s usually obvious where to fetch your data. The ‘norm’ is to fetch the data you need for that entire page at the point it’s first served.

Introducing Native Authentication for consumer mobile applications

Authentication experiences are the gateway to consumer applications. Friction in sign-up or sign-in has a direct impact on user onboarding, retention, and ultimately company revenue. These processes should be smooth and align with your brand’s identity to instill consumer confidence and trust. With that, we’d like to share some work we’re doing to make this easier and invite you to get an early look.

#1028 November 09, 2023
Audio Notes: Using Azure AI Speech to Perform Speech-to-Text Conversion

This is a new a SaaS experiment that uses artificial intelligence, speech to text, and text analytics to automatically summarise audio and create notes from your recordings.

Performance Improvements in ASP.NET Core 8

ASP.NET Core 8 and .NET 8 bring many exciting performance improvements. In this blog post, we will highlight some of the enhancements made in ASP.NET Core and show you how they can boost your web app’s speed and efficiency.

Building 3D Applications and Content with .NET MAUI and Evergine

Have you ever used an e-commerce platform and wished you could visualize products from any angle using a 3D representation instead of static images?

My 2023 C# Software Developer Tool List

I don’t think I have to make the point of how important tools are. What would we do without IDEs like Visual Studio? Or without good email clients like Gmail and Outlook?

Loading RSA Keys in .NET

System.Security.Cryptography.RSA has been the focus of many performance and usability improvements in recent major releases of .NET (and previously .NET Core).

#1027 November 02, 2023
C# Tip: Improve memory allocation by initializing collection size

Sometimes just a minor change can affect performance. Here’s a simple trick: initialize your collections by specifying the initial size!

A .NET distributed cache with a ~25 nanosecond read time!

This article described a .NET distributed cache library called Net.DistributedFileStoreCache (referred to as FileStore cache in this article).

The (long) journey to a better sharding multi-tenant application

This article focuses on the sharding approach of building a .NET multi-tenant application using the AuthPermissions.AspNetCore library (shortened to AuthP). After working exclusively on a sharding-only multi-tenant application I found various issues that make building and using such an application is difficult. This article describes the issues I found and the changes I made to the AuthP’s 6 release to improve sharding multi-tenant application.

Using the ROSLYN APIS to analyse a .NET solution

In this post, I want to revisit the topic from a fresh angle and demonstrate the foundations for achieving a slightly different goal.

How Async/Await Really Works in C#

This post is the first such follow-up, deep-diving into the history leading to, the design decisions behind, and implementation details of async/await in C# and .NET.

#1026 October 25, 2023
Audio Notes: Using Azure AI Speech to Perform Speech-to-Text Conversion

This is a new a SaaS experiment that uses artificial intelligence, speech to text, and text analytics to automatically summarise audio and create notes from your recordings.

Performance Improvements in ASP.NET Core 8

ASP.NET Core 8 and .NET 8 bring many exciting performance improvements. In this blog post, we will highlight some of the enhancements made in ASP.NET Core and show you how they can boost your web app’s speed and efficiency.

Building 3D Applications and Content with .NET MAUI and Evergine

Have you ever used an e-commerce platform and wished you could visualize products from any angle using a 3D representation instead of static images?

My 2023 C# Software Developer Tool List

I don’t think I have to make the point of how important tools are. What would we do without IDEs like Visual Studio? Or without good email clients like Gmail and Outlook?

Loading RSA Keys in .NET

System.Security.Cryptography.RSA has been the focus of many performance and usability improvements in recent major releases of .NET (and previously .NET Core).

#1025 October 18, 2023
Padding for Overlaid Structs

This time we’ll take a look at different techniques to add “padding” or “holes” in our overlaid structs.

Overhauled F# code fixes in Visual Studio

This summer, the F# code fixes in Visual Studio underwent significant updates.

C# Dev Kit – Now Generally Available

Today, we are thrilled to announce the general availability of C# Dev Kit, a Visual Studio Code extension that brings an improved editor-first C# development experience to Linux, macOS, and Windows.

Customizing the name of embedded resources in .NET

When you use embedded resources in a .NET project, the resource name is computed from the path of the file.

Memory-Mapped Files and Overlaid Structs

It has been a long, long time since I’ve used memory-mapped files - I think the last time was before .NET existed (!).

#1024 October 02, 2023
Announcing .NET 8 Preview 7

.NET 8 Preview 7 is now available. We’re already at the final preview release for .NET 8 and will now shift to release candidates. Almost all new features for the release are in their final shape.

Validating nested DataAnnotation IOptions recursively with MiniValidation

In this short post I show how you can use the MiniValidation library from Damian Edwards to support recursive validation of IOptions object in .NET 6+.

Get HTML color codes

Find that perfect color with our color picker and discover beautiful color harmonies, tints, shades and tones; input Hex color codes, RGB and HSL values, and generate HTML, CSS and SCSS styles.

C# 12: Collection literals

A new feature is hitting C# 12 and it is called Collection literals. In this blog post, I will show you what it is and how it works.

Hot Reload in Windows Applications

CreateNewOnMetadataUpdate attribute to force updating of entire classes, rather than patching existing types. This makes hot reload more resilient but does require additional logic in order to apply the newly created types.