Error Prone .NET

July 2, 2025 ยท View on GitHub

ErrorProne.NET is a set of Roslyn-based analyzers that will help you to write correct code. The idea is similar to Google's error-prone but instead of Java, the analyzers are focusing on correctness (and, maybe, performance) of C# programs.

Installation

Add the following nuget package to you project: https://www.nuget.org/packages/ErrorProne.NET.CoreAnalyzers/

Rules

Rules

Async Analyzers

IdDescription
EPC14ConfigureAwait(false) call is redundant
EPC15ConfigureAwait(false) must be used
EPC16Awaiting a result of a null-conditional expression will cause NullReferenceException
EPC17Avoid async-void delegates
EPC18A task instance is implicitly converted to a string
EPC26Do not use tasks in using block
EPC27Avoid async void methods
EPC31Do not return null for Task-like types
EPC32TaskCompletionSource should use RunContinuationsAsynchronously
EPC33Do not use Thread.Sleep in async methods
EPC35Do not block unnecessarily in async methods
EPC36Do not use async delegates with Task.Factory.StartNew and TaskCreationOptions.LongRunning
EPC37Do not validate arguments in async methods

Generic Bugs and Code Smells

IdDescription
EPC19Observe and Dispose a 'CancellationTokenRegistration' to avoid memory leaks
EPC20Avoid using default ToString implementation
EPC28Do not use ExcludeFromCodeCoverage on partial classes
EPC29ExcludeFromCodeCoverageAttribute should provide a message
EPC30Method calls itself recursively
ERP041EventSource class should be sealed
ERP042EventSource implementation is not correct

Concurrency

IdDescription
ERP031The API is not thread-safe

Error Handling Issues

IdDescription
EPC11Suspicious equality implementation
EPC12Suspicious exception handling: only the 'Message' property is observed in the catch block
EPC13Suspiciously unobserved result
EPC34Method return value marked with MustUseResultAttribute must be used
ERP021Incorrect exception propagation
ERP022Unobserved exception in a generic exception handler

Performance

IdDescription
EPC23Avoid using Enumerable.Contains on HashSet
EPC24A hash table "unfriendly" type is used as the key in a hash table
EPC25Avoid using default Equals or HashCode implementation from structs