Search

How to Update appsettings.json in C#
By Tan Lee Published on Mar 06, 2025 431

To update values programmatically within a settings JSON file, you will need to overwrite the entire settings.json file.

Read more
Injecting ILogger into Dapper Polly Retry Policy in C#
By Tan Lee Published on Mar 11, 2025 234

To inject ILogger into a Dapper Polly Retry Policy in C#, you can follow these steps.

Read more
Properly Disposing HttpContent When Using HttpClient in C#
By Tan Lee Published on Mar 11, 2025 180

In versions prior to .NET Core 3.0 (including .NET Framework), database connection pooling was automatically managed by the framework, with the connection object being disposed of at the end of each operation.

Read more
How to send a file with HttpClient in C#
By Tan Lee Published on Mar 11, 2025 345

When uploading a file with HttpClient, you need to place the file inside a MultipartFormDataContent object, which will be sent as the body of the HTTP request.

Read more
How to Deserialize JSON with quoted numbers in C#
By Tan Lee Published on Mar 11, 2025 238

In JSON, numbers can be represented in two main formats: as literal numbers (e.g., 123) or as quoted strings (e.g., "123").

Read more
How to Configure HttpClient connection keep-alive in C#
By Tan Lee Published on Mar 11, 2025 395

When using a single instance of SqlConnection to interact with a database, the connection is pooled, meaning it can be reused for subsequent requests to improve performance.

Read more
How to add request headers when using HttpClient in C#
By Tan Lee Published on Mar 11, 2025 339

When using HttpClient to send requests in C#, there are two primary ways to add headers:

Read more
How to Delete records with Dapper in C#
By Tan Lee Published on Mar 10, 2025 229

In C#, you can use Dapper to delete records from a database by executing a DELETE statement with the Execute() method, passing in the record identifier as a parameter.

Read more
How to Execute a SELECT query with Dapper in C#
By Tan Lee Published on Mar 10, 2025 281

You can query a database in C# using Dapper by executing a SELECT query with the Query() method, specifying the type to map the results to, and optionally adding parameters.

Read more
How to Get inserted identity value with Dapper in C#
By Tan Lee Published on Mar 10, 2025 320

When inserting a record into a table that has an identity column, the database automatically generates a value for that column. To retrieve the identity value after the insert, you can use the OUTPUT INSERTED. clause in your SQL query.

Read more
How to Create overlay modal popup in C#
By Tan Lee Published on Jul 16, 2024 9.08K

Creating an overlay modal dialog in a C# Windows Forms Application involves several steps.

Read more
Hide URL in Popup Window with window.open
By Tan Lee Published on Feb 08, 2025 399

If you're using the window.open() method to open a popup on your website, the URL of the opened window often appears in the address bar.

Read more
How to Center a Popup Window on Screen
By Tan Lee Published on Feb 08, 2025 179

You can use JavaScript's window.open() method to create and center a popup window. By setting the correct values for left and top, we can position the window in the middle of the screen.

Read more
How to undo the changes in Entity Framework
By Tan Lee Published on May 28, 2024 1.32K

Implementing an undo/redo feature for a DbContext in Entity Framework (EF) is a challenging task because Entity Framework does not provide built-in support for undo/redo operations.

Read more
How to fix 'IMvcBuilder' does not contain a definition for 'AddNewtonsoftJson'
By Tan Lee Published on Jun 21, 2024 3.96K

The error message you are seeing, "IMvcBuilder does not contain a definition for AddNewtonsoftJson", typically occurs when you're trying to add Newtonsoft.Json support to an ASP.NET Core MVC application, but the necessary package or using directive is missing.

Read more
How to setup a webapi controller for multipart/form-data
By Tan Lee Published on Feb 16, 2024 812

If you uploaded file through webapi in angularjs and encountered the following error: ExceptionMessage=No MediaTypeFormatter is available to read an object of type ‘HttpPostedFileBase’ from content with media type 'multipart/form-data'.

Read more
How to get unix timestamp in C#
By Tan Lee Published on Jul 11, 2024 2.23K

In C#, you can get the Unix timestamp, which represents the number of seconds that have elapsed since January 1, 1970 (Unix epoch), in a couple of ways.

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 - Aggregate SELECT queries
By Tan Lee Published on Feb 06, 2025 124

In this article, I’ll demonstrate how to use EF Core to aggregate data from a table, group it by a specific category, and apply conditions to include only certain groups.

Read more
Tuples in C#
By Tan Lee Published on Feb 06, 2025 179

This guide introduces Tuples in C#, offering an exploration of their key features and uses. It aims to provide a thorough understanding of Tuples, highlighting their significance as a versatile and powerful data structure in C#.

Read more
How to send a file using HttpClient in C#
By Tan Lee Published on Jan 22, 2025 444

When working with HTTP requests in C#, one common task is sending files through a POST request.

Read more
Sending query strings using HttpClient in C#
By Tan Lee Published on Jan 21, 2025 481

Query strings consist of a ? followed by one or more key-value pairs separated by &. It is essential to ensure that special characters, such as spaces or Unicode characters, are properly encoded.

Read more
The referenced component could not be found
By Tan Lee Published on Jan 21, 2025 353

When opening a C# project in Visual Studio, you may encounter a frustrating error where none of the references load correctly.

Read more
Fixing the Sync over Async Antipattern in C#
By Tan Lee Published on Jan 21, 2025 236

One common mistake developers make is the Sync over Async antipattern, which occurs when blocking waits are used in asynchronous methods instead of awaiting them properly.

Read more
C# Remove items from dictionary
By Tan Lee Published on Jan 21, 2025 313

Dictionaries store key/value pairs. To remove one or more items from a dictionary, you can use the following methods:

Read more
Adding dynamic parameters with Dapper in C#
By Tan Lee Published on Jan 18, 2025 442

When executing queries using Dapper, passing dynamic parameters can be done easily with a Dictionary.

Read more
C# EventHandler
By Tan Lee Published on Jan 18, 2025 259

Events are a core implementation of the observer pattern and consist of two main components:

Read more
How to fix 'InvalidOperationException: Scheme already exists: Bearer'
By Tan Lee Published on Jan 17, 2025 715

The System.InvalidOperationException: Scheme already exists: bearer error typically occurs when you're working with authentication in a .NET application, and you've registered the Bearer authentication scheme multiple times, which causes a conflict.

Read more
How To Auto Ellipse Text in C#
By Tan Lee Published on Jan 16, 2025 326

When developing applications in C#, one common requirement is to handle text that exceeds the available space in a UI element, like a label or a text box.

Read more
Editing the Windows Registry in C#
By Tan Lee Published on Jan 16, 2025 431

In this tutorial, we'll explore how to edit the Windows registry using C#. We will cover the steps to create new keys and values, as well as modify existing ones.

Read more