How To
How to ignore JSON deserialization errors in C#
By Tan Lee Published on Mar 13, 2025 335
A single deserialization error can cause the entire process to fail.
JsonException: A possible object cycle was detected
By Tan Lee Published on Mar 13, 2025 217
When serializing objects in .NET, you may encounter a JsonException due to circular references between objects.
JSON value could not be converted to System.String in C#
By Tan Lee Published on Mar 13, 2025 365
When you send a request to an ASP.NET API with a JSON body, you might encounter the following exception:
Calling ‘BuildServiceProvider’ from application code results in an additional copy of singleton services being created
By Tan Lee Published on Mar 13, 2025 302
When calling BuildServiceProvider() in your application, you may encounter this warning:
How to use Newtonsoft in ASP.NET Core
By Tan Lee Published on Mar 13, 2025 210
To use Newtonsoft.Json in an ASP.NET Core application instead of the default System.Text.Json, follow these steps:
How to use Polly In C#
By Tan Lee Published on Jan 09, 2025 462
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.
Global exception event handlers in C#
By Tan Lee Published on Mar 12, 2025 181
In .NET applications, there are two essential global exception events that can help you manage errors:
How to Add or overwrite a value in ConcurrentDictionary in C#
By Tan Lee Published on Mar 12, 2025 228
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.
Handling Posted Form Data in an API Controller
By Tan Lee Published on Mar 12, 2025 210
To capture posted form data in an API Controller (using the [ApiController] attribute) in ASP.NET Core, use parameters with the [FromForm] attribute.
How to Add a custom action filter in ASP.NET Core
By Tan Lee Published on Mar 12, 2025 204
Action filters in ASP.NET Core provide a way to inspect HTTP requests before they reach the action method and responses before they are sent back to the client.
How to Get all classes with a custom attribute in C#
By Tan Lee Published on Mar 12, 2025 242
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.
How to Map query results to multiple objects with Dapper in C#
By Tan Lee Published on Mar 12, 2025 373
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.