How To
Parsing a DateTime from a string in C#
By Tan Lee Published on Mar 14, 2025 708
In C#, you can convert a string to a DateTime using the following methods:
How to batch read with Threading.ChannelReader in C#
By Tan Lee Published on Mar 13, 2025 551
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.
How to ignore JSON deserialization errors in C#
By Tan Lee Published on Mar 13, 2025 688
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 441
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 861
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 663
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 456
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 807
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 406
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 459
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 396
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 406
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.