Search

Try/finally with no catch block in C#
By Tan Lee Published on Mar 14, 2025 175

In C#, a try/finally block is particularly useful when you need to guarantee certain actions will always be executed at the end of a method, regardless of whether an exception was thrown.

Read more
Parsing a DateTime from a string in C#
By Tan Lee Published on Mar 14, 2025 340

In C#, you can convert a string to a DateTime using the following methods:

Read more
How to batch read with Threading.ChannelReader in C#
By Tan Lee Published on Mar 13, 2025 235

In scenarios involving a consumer/producer model, batching the consumption of items can be highly beneficial. Whether you’re inserting a bulk of records into a database or sending multiple data packets over HTTP, sending individual items one by one can be inefficient.

Read more
How to ignore JSON deserialization errors in C#
By Tan Lee Published on Mar 13, 2025 287

A single deserialization error can cause the entire process to fail.

Read more
JSON value could not be converted to System.String in C#
By Tan Lee Published on Mar 13, 2025 344

When you send a request to an ASP.NET API with a JSON body, you might encounter the following exception:

Read more
How to use Polly In C#
By Tan Lee Published on Jan 09, 2025 430

To use Polly in C#, you'll need to install the Polly NuGet package and implement it in your code for retry, circuit breaker, timeout, and other resiliency patterns.

Read more
Global exception event handlers in C#
By Tan Lee Published on Mar 12, 2025 172

In .NET applications, there are two essential global exception events that can help you manage errors:

Read more
How to Add or overwrite a value in ConcurrentDictionary in C#
By Tan Lee Published on Mar 12, 2025 222

The ConcurrentDictionary is a thread-safe collection, which allows you to safely add, retrieve, or modify items from multiple threads. You can use the indexer to add or overwrite a value easily, but there are times when you might want to handle your operations more selectively depending on your requirements.

Read more
How to Get all classes with a custom attribute in C#
By Tan Lee Published on Mar 12, 2025 232

To find all classes with a custom attribute, the first step is to gather all types within the assembly and then use the IsDefined method to filter the types that are marked with the custom attribute.

Read more
How to Map query results to multiple objects with Dapper in C#
By Tan Lee Published on Mar 12, 2025 357

When dealing with SQL queries that join multiple tables, Dapper's multi-mapping feature allows you to map the results to multiple objects. This can be really handy when you're pulling related data in a single query.

Read more
Using Entity Framework with IDbContext in .NET 9.0
By Tan Lee Published on Feb 21, 2025 300

Entity Framework (EF) Core is a powerful ORM for managing databases in .NET applications. While EF Core provides ease in interacting with databases, directly using DbContext in services or repositories can create tight coupling and make unit testing more challenging.

Read more
How to Upload and Display Image In PictureBox Using C#
By Tan Lee Published on Jul 17, 2024 11.48K

To upload and display an image in a PictureBox control in a C# Windows Forms Application, you can follow these steps.

Read more
How to implement Sciter in C#
By Tan Lee Published on Feb 15, 2025 225

Learn how to integrate and set up Sciter, a lightweight HTML and CSS UI engine, in your WinForms application.

Read more
Billion Laughs XML DoS Attack on .NET Framework C# Xml Parser
By Tan Lee Published on Feb 14, 2025 177

The Billion Laughs attack is a denial-of-service (DoS) vulnerability targeting XML parsers, particularly those that support Document Type Definition (DTD).

Read more
How to allow only plain text inside a RichTextBox in C#
By Tan Lee Published on Feb 14, 2025 216

By default, most rich text boxes do not support pasting text through drag and drop.

Read more
Restoring MySQL Databases with mysqldump
By Tan Lee Published on Feb 14, 2025 101

An effective backup and restore strategy is crucial for ensuring the protection, integrity, and consistency of your data.

Read more
Download backup of Northwind database for SQL Server
By Tan Lee Published on Nov 13, 2024 515

To get the Northwind sample database for SQL Server, you can follow one of the steps below.

Read more
How to Create a Setup file using Advanced Installer
By Tan Lee Published on May 16, 2024 5.19K

Creating a setup file using Advanced Installer is a straightforward process, but it involves several steps.

Read more
How to Remove Duplicates from a List with LINQ in C#
By Tan Lee Published on Jan 10, 2025 908

In C#, LINQ provides a simple way to remove duplicates from a list.

Read more
How to fix 'Authorization in ASP.NET Core' with 401 Unauthorized
By Tan Lee Published on Jun 10, 2024 1.8K

Getting a 401 Unauthorized error when using the [Authorize] attribute in ASP.NET Core generally indicates that there is an issue with the authentication or authorization setup.

Read more
Working with HTMX and Razor Components
By Tan Lee Published on Feb 07, 2025 243

In .NET 8, working with Razor components has become an efficient way to handle HTML rendering in a clean and reusable format.

Read more
How to fix 'Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on'
By Tan Lee Published on Jul 08, 2024 1.74K

The error "Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on" typically occurs in multi-threaded applications when you try to update or interact with UI controls from a thread other than the one that created those controls.

Read more
EF Core - SELECT Queries Involving Multiple Tables
By Tan Lee Published on Feb 06, 2025 151

When you design a database with related tables, it’s common to need data from more than one table or filter records based on values from another table.

Read more
How to replace a file in C#
By Tan Lee Published on Jun 12, 2024 829

Replacing a file in C# can be done using the System.IO namespace, which provides classes for working with files and directories.

Read more
InvalidOperationException: Unable to resolve service for type
By Tan Lee Published on Feb 04, 2025 646

When the built-in dependency injection framework attempts to create an object, it needs to resolve all constructor parameters.

Read more
How to add custom middleware in ASP.NET Core
By Tan Lee Published on Feb 04, 2025 328

In ASP.NET Core, the request pipeline is a series of middleware components that handle HTTP requests.

Read more
How to Use Cancellation Tokens in ASP.NET Core
By Tan Lee Published on Feb 03, 2025 299

ASP.NET Core 7, the latest version of Microsoft's open-source web application framework, brings many advanced features from previous .NET versions, one of which is cancellation tokens.

Read more
How to Record voice in C#
By Tan Lee Published on Jun 12, 2024 11.45K

To record audio from a microphone in C# Windows Forms Application, you can use the Win32 API.

Read more
How to record audio from microphone in C#
By Tan Lee Published on Jul 13, 2024 2.67K

To record audio from a microphone in C#, you can use the NAudio library, which is a popular library for working with audio in .NET.

Read more
How to Copy a Selected Row From one DataGridView to another DataGridView in C#
By Tan Lee Published on Aug 13, 2017 13.58K

Copy selected row from one DataGridView to another DataGridView in C#

Read more