Exception Rethrow traps in .NET Framework

In my investigation of a production issue in a .NET Framework application, I faced a challenge while trying to match the stack trace from error logs to the source code. Despite .NET documentation stating to keep the original stack trace information with the exception, use the throw statement without specifying...

Learn C# Enum Flags by Doing

Ever tried naming your favorite things using enums in C#/.NET, like choosing between Dog, Cat, or Bird for your favorite pet, or picking your top language from English, German, Ukrainian? Enums are fantastic for this - like a personal pick-n-mix of named values. But here’s the twist: what if you’re...

Handling of unknown enums in .NET serialization for API integration

Enumerations, or Enums, serve as a comprehensive method for representing named values, such as currencies (e.g., EUR, USD, NOK) and languages (e.g., English, German, Spanish). They are integral to the vast majority of programming languages. Additionally, OpenAPI (Swagger) accommodates Enums through its utilization of JSON, a subset of JavaScript. However,...

Speed up NUnit tests in one-line

Nowadays, software developers use laptops with lots of CPU cores. The same on server frames - the number of CPUs grows. As a developer, I expect that the libraries I use are optimized to distribute workload across multiple CPU cores by default. But it is not the case for NUnit...

Compute SHA hash for streams

We have a generic logic to log all requests towards API. Due to security reasons, we cannot log the request body because it can contain sensitive data or personal identifiable information (PII) such as customer emails, names, passwords, etc. To distinguish requests, we have decided to hash a request body...

Beware of decimals in Microsoft SQL Server

Every year, we adjust prices for services according to the inflation rate and some business requirements. This year we have got new requirements to increase and round the prices according to specific business rules. We use Microsoft SQL Server and the prices are stored there. To update prices we should...

Lessons learned from running the company for a year

This is a story about a software programmer without any experience in business, who managed to open a company and survived for 1 year in Poland. There are highlights below I have encountered. But before diving into details let’s revile how this idea has popped up. Background Almost 5 years...

Review .NET dependencies on every commit

I want to share with you a sad story that would not have happened if I had known earlier how to review .NET dependencies automatically. I work with .NET app that has a lot of .NET Framework projects. However, they are slowly being migrated to .NET Standard to be able...

.NET type for personally identifiable information (PII)

At some point, I started to feel discomfort working with personally identifiable information data in our project. Mostly, because it is a relatively new field and not always straightforward. In this article, I’m going to try to tackle the main issues and make the implicit explicit. Personally identifiable information (PII)...

Duty bot via Google Sheets

Who’s on duty today? Yeah, it always takes me to school time. However, this keeps sounding over and over again during software development. Because, our team has a support duty to quickly respond to technical questions by the support team, follow logs, and system health. Usually, it is a boring...

Pitfalls of parsing .NET enumeration. Is Enum.Parse broken?

Nope, Enum.Parse is not broken, it is a feature, not a bug :) However, you have to know its pitfalls. Before deep dive let’s warm up a bit. What is enumeration? Enumerated type is a data type consisting of a set of named values. The enumerator names are usually identifiers...

Audit log via transactional outbox

I’m working on a project with a data-centric approach mostly. Well, as it happens historically ;) Frequently, I’m keep asked to figure out when and who changed entity state. In most cases, I have no clue because the application was not designed to record such things. Ideally, the application is...

Secure appsettings.json with ease

Nowadays, it is almost impossible to implement a self-containing application. Even a small web application requires at least a database and email provider. Or maybe even more such as URL to SFTP partner, SSL certificate for server-to-server communication, API keys for integration with 3rd parties. All those data is a...

Using Blazor WebAssembly in the old ASP.NET

The building of a rich user interface is not always easy for .NET developers, especially if you dive deep to use React, Angular, webpack and friends. Blazor gives a nice trade-off bringing Razor-like templates and C# to a browser utilizing WebAssembly. Blazor is a free and open-source web framework that...

Job scheduler via Azure Service Bus

There are many kinds of jobs that applications can run regularly. For instance: renewing subscriptions for paying users on the first of every month downloading new data from partner systems every X minutes sending reminder or close subscriptions for high-debt users jobs related to well-known events like opening/closing stock exchange,...

The smallest file server on C# to save data from a dying Linux

One evening after a couple of hours of battle in Age of Empires when I felt like a winner, I came up to the conclusion that I must upgrade Ubuntu on a DigitalOcean droplet. I had the droplet with Ubuntu 16.04 to run app.gaevoy.com. It was 23:00 and I thought...

Story on how MiniProfiler 3 breaks TransactionScope flow

Usually, while investigating some strange behavior I feel like I’m the detective Columbo and the murderer at the same time :) Debugging is like being the detective in a crime movie where you are also the murderer — Filipe Fortes This time, I noticed strange behavior on how TransactionScope flows....

Mocking via interface vs delegate vs virtual method in C#

Quite often, I face a dilemma on how to mock a single method. It looks like overengineering for nothing, when the method is being moved outside of the class, just to mock it afterward. But what alternatives do we have? Before answering the question let’s consider a specific code example....

Respect the order of .NET Enum values or how to rename them correctly

Have you tried to rename Enum values if their string representation stored in database or messages? For instance, Colors enumeration is public enum Colors { Red = 1, Green = 2, Blue = 3, Black = 4 } Hence, I would like to rename Black to White. ಠ_ಠ No no,...

ASP.NET MVC app warm-up

I’m pretty sure you have seen application slow down just after deploying yet another release into production. Yeah, that’s a side effect of using one of the just-in-time compilation-based languages such as C# or Java. But not only JIT is guilty in a slow cold start. But also an initialization...