Managing resources effectively in .NET is critical for both application stability and performance. In this post, we’ll explore the proper use of the IDisposable pattern, guidelines for when to dispose objects using a using statement, and some pitfalls of disposing objects blindly—such as disposing shared resources. Understanding IDisposable The IDisposable interface provides a standardized way …
.Net
.NET is a large collection of a bunch of different things really; including compilers, runtimes, programming languages and a bunch of different tools and technologies.
It provides a lot of common functionality that can be tapped into rather than recreating it from scratch.
C# is one language that can be used on .NET. It get compiled initially by Roslyn and can get additional compilation at runtime by RyuJIT. Other languages include F#, which can all be compiled and run against its runtimes.
This works because it’s generally not compiled to a particularly low level language but rather to an Intermediate Language that can be executed by a .NET runtime. The runtime then does the appropriate translations to actual system/hardware calls allowing you to not have to worry about it.
When you create at least C# projects, you have to specify what runtime you’re targeting so that it can be compiled appropriately to work; not just whether it’s Framework or Core, but also the version number since functionality of the same thing may be different.
One of the goals with .NET 5+ is to reduce the confusion by bringing many of the parts together under one umbrella, but it’s going to be a while before that replaced enough existing software to really get rid of the confusion (especially since .NET 5 isn’t going to have Long Term Support).
Entity Framework Core and LINQ Best Practices for C#
Entity Framework makes data access easy to write, and that’s also what makes it easy to write badly. A query that’s instant against a few test rows can bring the database to a crawl once it hits production data, and the C# often looks perfectly fine. This is my reference list of LINQ and Entity …
C# Async and Parallel Programming Best Practices
I’ve written about asynchronous and parallel programming before, in the seven most common async mistakes and what SynchronizationContext is. Few topics in C# produce as many subtle bugs. Deadlocks only show up on the UI thread, exceptions disappear from async void methods, and race conditions never happen on your machine and happen every day in …
Sharing Clients in Duende IdentityServer: Security Risks
Years ago I built authorization on the open-source IdentityServer4 (I wrote about that here). Its successor, Duende IdentityServer, is a commercial product, and its pricing depends on how many clients you configure. For a company that ships its software for customers to install on their own servers, instead of running it as SaaS, there’s also …
Thread Affinity in .NET: When CPU Pinning Helps and How to Use TPL
Thread affinity means restricting a thread to run only on certain CPU cores. Without it, the operating system’s scheduler can move a thread from one core to another as it balances the load across the machine. The idea behind pinning a thread is cache locality: a thread that stays on one core keeps its working …
When to Use Inheritance in C# (and When to Avoid It)
Inheritance is the feature most object-oriented programmers learn first. It’s also one of the most misused. Used well, it gives you a single abstraction that many types can stand behind, and calling code that never needs to know which one it has. Used badly, it gives you hierarchies five levels deep, base classes nobody dares …
How to use ConfigBuilders for User Secrets Management in Asp.Net MVC 5
When it comes to storing our app secrets, Asp.Net Core has a built-in mechanism to do that out of the box. But this is not the case for Asp.Net MVC 5. For MVC 5, we need to install custom configBuilders packages in order to be able to have the same functionality. There are many other …
How to Customize Windows Terminal and PowerShell Using Fzf, Neovim and Beautify it with Oh My Posh
PowerShell on its own it a very powerful tool. But what if told you can make it even better using some tools that you can install on it? Not only that but you can also make it more beautiful/handsome, perhaps with a bit of a personal touch too? So, in this post I’m going to …
Color Coder: Using Roslyn APIs For Syntax Highlighting
Couple of years ago, I’ve created a Visual Studio extension to colorize things in C#. More specifically I was trying to colorize different programming constructs such as extension methods. So it had to be done in a syntax aware manner as oppose to coloring text. For that I used Roslyn .NET compiler to do this. …
Careful Model Binding JavaScript ISO Date Format to DateTime
It is agreed by the .Net community that DateTime should not be used when we develop .Net applications. You can read more about why that here. In short the least we can do is to use DateTimeOffset instead. But this post is not about the common problems associated with using DateTime. But rather it’s about …
