How To

How to Deserialize JSON with a specific constructor in C#
By Tan Lee Published on Mar 07, 2025 339

When your class has multiple constructors, the JsonConstructor attribute allows you to specify which one to use during JSON deserialization.

Only one parameter per action may be bound from body in ASP.NET Core
By Tan Lee Published on Mar 07, 2025 253

When working with web APIs in ASP.NET Core, you might encounter an error when multiple parameters in your action method are bound to the request body.

The request matched multiple endpoints in ASP.NET Core
By Tan Lee Published on Mar 07, 2025 229

When you send a request to an endpoint, you might encounter the following error response:

How to Create a custom model validation attribute in ASP.NET Core
By Tan Lee Published on Mar 07, 2025 185

ASP.NET Core offers many built-in model validation attributes, such as [Required] and [StringLength], that can handle a majority of validation scenarios.

How to use SortedSet in C#
By Tan Lee Published on Mar 07, 2025 134

If you need to maintain a collection of elements that must always stay in sorted order while continuously adding new ones, the SortedSet class in C# is an excellent choice.

How to Connect to a MySQL database in C#
By Tan Lee Published on Mar 07, 2025 162

The easiest way to connect to a MySQL database in a .NET project is by using the MySql.Data package (from Oracle).

How to read the Description attribute in C#
By Tan Lee Published on Mar 07, 2025 130

The Description attribute in C# can be used to provide descriptive information about types and their members (such as properties and methods). A common use case is associating user-friendly descriptions with enum values.

How to Call a constructor from another constructor in C#
By Tan Lee Published on Mar 07, 2025 163

In C#, when you need to call one constructor from another, you can use constructor chaining syntax.

How to read problem details JSON with HttpClient in C#
By Tan Lee Published on Mar 07, 2025 211

When working with APIs, error responses are often standardized using the Problem Details format (RFC7807), which has a Content-Type of application/problem+json.

Deserialization from CodeDOM format is unsafe and has been disabled
By Tan Lee Published on Mar 07, 2025 290

To fix the DevExpress.XtraReports.Security.CodeDomLayoutDeserializationRestrictedException: 'Deserialization from CodeDOM format is unsafe and has been disabled.', you need to enable CodeDOM report deserialization explicitly or migrate to XML serialization.

How to Get Status Codes with HttpClient in C#
By Tan Lee Published on Mar 06, 2025 470

When using HttpClient to send requests, you can easily access the status code from the HttpResponseMessage object.

How to use TimeZoneInfo in C#
By Tan Lee Published on Mar 06, 2025 440

Time zones can be tricky due to their varying rules and changes, so leveraging a library is a smart approach. In .NET, one such option is the built-in TimeZoneInfo class.