11 C# Libraries for Developers

C# offers libraries that are used by millions of projects. Libraries make your life easier because you won’t reinvent the wheel. The primary purpose of a developer is to solve a particular problem, not to find solutions for many issues.

Dapper

Dapper was built by StackExchange, which also created StackOverflow, and it’s an alternative to Entity Framework. This ORM is faster than Entity Framework, but you must write your queries. So, if you like to write SQL and hate the queries that Entity Framework generates for you, then Dapper is the best choice.

AutoMapper

When you must map one object to another, then AutoMapper is the first choice. Whenever you need to copy the properties of an object to a DTO, then AutoMapper can do it for you. Automapper has some great features:

  • Mapper Profiles
  • Dependency Injection
  • Custom Mapping Methods

Serilog

Serilog is the most popular library for logging in .NET. You can configure Serilog to display your logs in the console, files, database, etc… You can set different types of importance for each log like verbose, debug, info, warning, error, and fatal.

Swashbuckle Swagger

Swagger is a way to create documentation automatically for your RESTful APIs. The interface is built using the help of OpenAPI, which gives the option to understand the services without the source code.

Swagger interface
Swagger Interface

MiniProfiler

MiniProfiler can help you quickly identify how fast a page is loading and what parts of your code need more time to execute. You can see how many SQL queries are generated and the code for them.

MiniProfiller

MiniProfiler, like Dapper, is built by StackExchange, so expect something well-built. Regardless of the project, this is the first library I have included.

Hangfire

Hangfire is your first choice when you need to run tasks in the background. It keeps the tasks that should run in the database, so your jobs will not be lost if something wrong happens. You have evidence of the tasks that didn’t end successfully.

There are different jobs: delayed, fire-and-forget, recurring, or continuations. In the paid version, you also can run batches.

Polly

Sometimes you call an external service that can give you failures without a logical reason, for example, a service that is heavily called, then you need something to retry. Polly is the most important library to execute failure calls again.

This is a resilience library that has multiple policies available:

  • Retry: until it’s successfully or exceeds the limit number of calls
  • Circuit breaker for some time
  • Set a timeout period or how much a task can be retried
  • Fallback
  • Return the result from the cache if the call is similar
  • Bulkhead isolation

RestSharp

For REST API calls, RestSharp is a perfect choice.

You can also use it to send simple HTTP requests. RestSharp is the first choice when you need an HTTP client in C#.

This library has over 70 million downloads.

CSV Helper

Whenever you need to read or write a CSV File, you can use CsvHelper. It’s easy to use, and you can use it using classes or dynamics.

CSV Helper is the fastest C# library for manipulating separated value files.

Fluent Validation

As the name says, this library can build validations and rules for an object using fluent syntax. You can validate business objects using the built-in validators or make your own business rules.

HtmlAgilityPack

This is an HTML parser for C# that can download web pages and load them in memory. You can perform queries using XPath or the library’s built-in methods.

Using HTML Agility Pack, you can build spiders that can get what data you need.

4 thoughts on “11 C# Libraries for Developers”

Leave a Comment