C#, Tools

3rd party open source .NET libraries to add to your toolbox

6 min read

It’s always a pleasure to see the community help each other out in ways we think are unimaginable. One of the best way some people help, is to open source their hard work into libraries, so you don’t have to code the behavior yourself. It’s always hard to know what’s out there, so in this post, I want to give a shootout to some of the .NET libraries I find could definitely enhance your application(s) and if not, beef up your toolbox. As a developer, it’s good to know they exist, so you can increase your knowledge of the available tools out there. They definitely can help you out in the future.

Note that I am listing here some libraries that I use and used and some that I could see myself using in the future if need be. Be aware that those are not the only libraries available around. Contributors did a good job listing quite a few (a lot of them!) here so you should definitely have a look at what is being developed.

If you find bugs, please report them and even better if you can fix them and make a pull request! You can only help others that way!

Edit (2017-08-27): Added Refit and and refactored Autofac into a DI/IOC Container section along with adding library SimpleInjector in the list. Thanks to the comments!

General:

Polly:

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner.

Transient faults are errors that occur because of some temporary condition such as network connectivity issues or service unavailability. Typically, if you retry the operation that resulted in a transient error a short time later, you find that the error has disappeared 1.

Polly allows you to handle such errors and to define policies (actions) on what to do when such errors occur. Be careful, however, on what you define as a transient error.

Jot:

Jot is a library for persisting and applying .NET application state. It decouples the dependence to Settings.Settings class/file. Great for desktop applications.

AutoMapper:

AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. What makes AutoMapper interesting is that it provides some interesting conventions to take the dirty work out of figuring out how to map type A to type B.

DI/IOC Containers:

Autofac:

Autofac is an Inversion Of Control (IOC) container.

SimpleInjector:

The goal of Simple Injector is to provide .NET application developers with an easy, flexible, and fast Dependency Injection library that promotes best practice to steer developers towards the pit of success.

It also works with ASP.NET Core.

Storage:

Dapper:

Dapper is a simple object mapper for your database. If you are not using Entity Framework and you are looking for a micro-ORM, Dapper is your friend.

StackExchange.Redis:

One of the best, if not the defacto Redis client to use to communicate with Redis.

Features

  • High performance multiplexed design, allowing for efficient use of shared connections from multiple calling threads
  • Abstraction over redis node configuration: the client can silently negotiate multiple redis servers for robustness and availability
  • Convenient access to the full redis feature-set
  • Full dual programming model both synchronous and asynchronous usage, without requiring “sync over async” usage of the TPL
  • Support for redis “cluster”

Processes and Command Line Interfaces (CLI):

CliWrap:

Provides a wrapper around command line interface executables.

Examples:

Execute a command and get standard output as a string:

Execute a command asynchronously:

Cancel execution:

Gt.SubProcess:

Similar to CliWrap, Gt.SubProcess provides other functionality to deal with sub processes

HangFire:

Hangfire is an open-source framework that helps you to create, process and manage your background jobs, i.e. operations you don’t want to put in your request processing pipeline such as:

  • mass notifications/newsletter
  • batch import from xml, csv, json
  • creation of archives
  • firing off web hooks
  • deleting users
  • building different graphs
  • image/video processing
  • purge temporary files
  • recurring automated reports
  • database maintenance

Security:

NWEBSec:

NWebsec consists of several security libraries for ASP.NET applications. These libraries work together to remove version headers, control cache headers, stop potentially dangerous redirects, and set important security headers. Consult the docs to learn how they work.

Visual Studio Addon:

Roselyn Security Guard:

Security Guard is a set of Roslyn analyzers that aim to help security audits on .NET applications. The idea is to have an analyzer (security), which can try to detect potential vulnerabilities in code like SQL injection, csrf, cryptography weaknesses, hard coded passwords, cross side scripting (XSS), etc.

Compression:

SharpZipLib:

Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform.

Benchmarking:

BenchmarkDotNet:

Curious about performance? This library will help you micro benchmark certain parts of your application.

Scientist.net:

Scientist.net is a great library to test out the outcome of new path/refactoring of your code without having to actually use in production. It lets you try your new code while using your old code.

You can then implement an in-memory publisher (logger) that will log the results of the before and after so you can test your results to see if they match your expectations.

Parsers:

It may happen that sometimes you need to parse stuff. Here are some parses that can be helpful.

HtmlAgilityPack:

This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don’t HAVE to understand XPATH nor XSLT to use it, don’t worry…).

AngleSharp:

AngleSharp is a .NET library that gives you the ability to parse angle bracket based hyper-texts like HTML, SVG, and MathML.

Newtonsoft JSON.Net:

One of the most popular, and defacto json serializer/deserializer in ASP.NET core.

CSVHelper:

CSVHelper is a library to read and write CSVFiles. No need to have a dependence on oledb jet engine or make your own parser.

Logging:

Serilog:

Simple .NET logging that focuses on fully-structured events. You can think of it as a simple ETW.

NLog:

NLog is a rich logging platform to help your log stuff.

Communication:

SSH.NET:

SSH.NET is a Secure Shell (SSH-2) library for .NET

FluentFTP:

FluentFTP is a fully managed FTP and FTPS library for .NET & .NET Standard, optimized for speed. It provides extensive FTP commands, File uploads/downloads, SSL/TLS connections, Automatic directory listing parsing, File hashing/checksums, File permissions/CHMOD, FTP proxies, UTF-8 support, Async/await support and more.

CoreFTP:

CoreFTP is a simple .NET FTP library written entirely in C#, it is targeted at netstandard 1.6, meaning it will run under .NET Core (which is also where it derives its name) and the full .NET framework. This package was inspired due to a lack of packages providing FTP functionality compiled with support for the netstandard API surface.

Refit:

The automatic type-safe REST library for .NET Core, Xamarin and .NET. It is a library heavily inspired by Square’s Retrofit library, and it turns your REST API into a live interface.