Code fixes
164 of the 266 rules carry a code fix. Run the fix from the IDE light bulb, or from the command line with dotnet format analyzers.
Rules with a code fix
| Category | Rule | Title |
|---|---|---|
| Design | E128001 | Use FileInfo/DirectoryInfo instead of string paths |
| Design | E128003 | Use TimeProvider instead of DateTime.Now / DateTimeOffset.Now |
| Design | E128004 | Use IHttpClientFactory instead of new HttpClient() |
| Design | E128005 | Seal classes that have no subclasses |
| Design | E128007 | Avoid async void methods (non-event-handler) |
| Design | E128008 | Avoid sync-over-async (.Result / .GetAwaiter().GetResult()) |
| Design | E128017 | Use primary constructor parameter directly |
| Design | E128019 | Do not pass CancellationToken by in reference |
| Design | E128021 | Do not use in modifier with ref struct parameters (default: Error) |
| Design | E128030 | Do not compare FileSystemInfo types by reference (default: Info) |
| Design | E128032 | Concrete-only DI registration with available interface |
| Design | E128036 | Task.Run wrapping async lambda — unnecessary thread pool hop |
| Design | E128042 | Convert.ToInt32/ToInt64 wrapping ExecuteScalar without null guard |
| Design | E128044 | Type implements IAsyncDisposable but not IDisposable |
| Design | E128048 | Use switch instead of if/else-if chain on enum values |
| Design | E128049 | Avoid [DynamicallyAccessedMembers] — suppress with justification if required |
| Design | E128050 | Use TimeSpan for time-duration values to avoid unit ambiguity (default: Error) |
| Design | E128052 | Use immutable collection interface instead of mutable concrete type (default: Info) |
| Design | E128053 | Use collection of FileInfo/DirectoryInfo instead of collection of string for file system paths |
| Design | E128058 | Return List<T> via .AsReadOnly() when exposing as IReadOnlyList<T> |
| Design | E128059 | Interface method parameter is unused in implementation (default: Error) |
| Design | E128060 | Return Dictionary<K,V> via .AsReadOnly() when exposing as IReadOnlyDictionary<K,V> |
| Design | E128061 | Use an immutable type for static readonly arrays |
| Design | E128074 | Readonly struct property should use init accessor |
| Design | E128080 | Use ByteSize for data-size values to avoid unit ambiguity (default: Error) |
| Design | E128082 | Do not unwrap ByteSize via cast |
| Design | E128087 | Static numeric field should not be incremented with ++/-- |
| Design | E128219 | Memberless abstract base with all derivation in one assembly should be closed |
| Design | E128220 | Union switch ends in a discard or var arm instead of a null arm |
| Design | E128225 | Abstract base with members is a closed hierarchy |
| Reliability | E128011 | [GeneratedRegex] missing matchTimeoutMilliseconds |
| Reliability | E128012 | RegexOptions.Compiled is redundant in [GeneratedRegex] |
| Reliability | E128013 | [GeneratedRegex] pattern has repeated wildcards |
| Reliability | E128014 | [GeneratedRegex] pattern has a repeated group that can split across iterations |
| Reliability | E128016 | DateTime.Parse/ParseExact missing DateTimeStyles parameter |
| Reliability | E128020 | Do not use in modifier with mutable structs |
| Reliability | E128023 | Avoid hardcoded /tmp path |
| Reliability | E128028 | Task.FromResult wraps sync I/O that has an async alternative |
| Reliability | E128031 | AddSingleton factory returns IDisposable |
| Reliability | E128033 | Options class bound via .Bind() has init-only property |
| Reliability | E128034 | Constructor news a DI-registered type — inject via DI instead |
| Reliability | E128035 | Concrete-type DI dependency without direct registration |
| Reliability | E128037 | Unbounded Task.WhenAll over async Select or a Task.Run list |
| Reliability | E128038 | Task.WhenAll async lambda missing CancellationToken propagation |
| Reliability | E128039 | Catch filter must exclude OperationCanceledException |
| Reliability | E128040 | Concurrency limit must be positive |
| Reliability | E128041 | JsonDocument.RootElement must not escape the document’s using scope |
| Reliability | E128051 | Broad catch in async HttpClient method missing OperationCanceledException handler |
| Reliability | E128056 | File existence check TOCTOU race condition |
| Reliability | E128057 | Unprotected cleanup in finally block |
| Reliability | E128064 | Disk write-then-read round-trip — use the in-memory value instead of reading back |
| Reliability | E128070 | Pool Rent() capacity must be bounded — guard with Math.Min |
| Reliability | E128076 | Materialize QuerySelectorAll result before iterating |
| Reliability | E128077 | TextContent string match requires a preceding length guard |
| Reliability | E128086 | ArrayPool buffer used as SqliteParameter value without Size |
| Reliability | E128092 | Use async File.*Async overload instead of sync method |
| Reliability | E128093 | Use async DbConnection/DbCommand *Async overload instead of sync method |
| Reliability | E128096 | Detect synchronous call to async local function via .Result or .Wait() |
| Reliability | E128099 | Wait for process exit with a provable timeout |
| Reliability | E128100 | Catch filter reads negated token state on OperationCanceledException |
| Reliability | E128101 | Verify process output file exists before use |
| Reliability | E128109 | stackalloc must be bounded and outside loops |
| Reliability | E128110 | Zero a pooled buffer in a finally block before Return |
| Reliability | E128155 | Mutating the loop source inside its own foreach |
| Reliability | E128159 | TaskCompletionSource without RunContinuationsAsynchronously |
| Reliability | E128161 | Path.Combine with a rooted or parent segment |
| Reliability | E128163 | ImmutableArray field left at its default |
| Reliability | E128172 | catch swallows an assertion failure |
| Reliability | E128175 | SemaphoreSlim wait with no finally release guarantee |
| Reliability | E128176 | Event subscription that keeps the subscriber alive |
| Reliability | E128179 | Options type bound from configuration with no validation call |
| Reliability | E128189 | GCHandle with no Free call |
| Reliability | E128190 | FileStream created without asynchronous I/O |
| Reliability | E128194 | Lazy<T> field without thread safety |
| Reliability | E128238 | Array comparison uses reference equality, not element equality |
| Reliability | E128250 | Private field assignment overwritten before a read |
| Reliability | E128269 | Declaration syntax read without a syntax tree check |
| Reliability | E128270 | Rented pooled buffer is never returned |
| Performance | E128009 | Use MinBy/MaxBy instead of OrderBy().First() |
| Performance | E128010 | Pass HttpCompletionOption.ResponseHeadersRead to HttpClient calls |
| Performance | E128015 | Use string interpolation instead of string.Format |
| Performance | E128018 | Use ToArray() instead of ToList() for read-only foreach |
| Performance | E128026 | Redundant HashSet allocation in FrozenSet creation |
| Performance | E128027 | Use FrozenSet/FrozenDictionary for static readonly collections |
| Performance | E128029 | Replace multi-string OR-chain with HashSet.Contains |
| Performance | E128066 | Linear lookup inside loop creates O(n²) complexity |
| Performance | E128067 | String concatenation in loop creates O(n²) allocations |
| Performance | E128068 | Sort operation inside loop creates O(n² log n) complexity |
| Performance | E128072 | Prefer SHA256.HashData() over SHA256.Create() (default: Info) |
| Performance | E128081 | Use StringBuilderPool instead of new StringBuilder() (default: Info) |
| Performance | E128083 | Use ImmutableCollectionsMarshal.AsImmutableArray instead of ImmutableArray.Create/CreateRange with ToArray |
| Performance | E128084 | Use CollectionsMarshal.AsSpan instead of List.GetRange or a list indexer loop |
| Performance | E128085 | Use foreach + AddRange instead of SelectMany.ToList |
| Performance | E128098 | Collapse chained or looped string.Replace calls into a single pass |
| Performance | E128102 | Use SearchValues<char> for IndexOfAny scans |
| Performance | E128116 | Do not use MethodImplOptions.AggressiveOptimization |
| Performance | E128117 | Use LibraryImport instead of DllImport |
| Performance | E128121 | Use SequenceEqual instead of an element-by-element loop |
| Performance | E128122 | Guard an expensive log argument with IsEnabled |
| Performance | E128123 | Use [GeneratedRegex] for a constant pattern |
| Performance | E128124 | Cache SearchValues in a static readonly field |
| Performance | E128131 | Parse UTF-8 bytes with the span overload instead of a decoded string |
| Performance | E128132 | Do not use a culture-aware comparer for a collection key |
| Performance | E128133 | Use an alternate lookup instead of a temporary string key |
| Performance | E128134 | Use BitOperations.PopCount instead of a shift loop |
| Performance | E128135 | Use TensorPrimitives instead of a sum, min, or max loop |
| Performance | E128140 | Use Span.Fill/Clear/CopyTo instead of an element loop |
| Performance | E128141 | Use a u8 literal instead of Encoding.UTF8.GetBytes |
| Performance | E128152 | Complexity past the e128_max_complexity ceiling (nested loops, recursion) |
| Performance | E128205 | Collection filled in a loop has a known final count |
| Performance | E128207 | Reflection lookup inside a loop |
| Performance | E128208 | ContainsKey then indexer on a ConcurrentDictionary |
| Performance | E128209 | GetBytes(...).Length inside a loop allocates a byte array for its length |
| Performance | E128210 | new Regex inside a loop with a loop-invariant pattern |
| Performance | E128212 | ToCharArray result used only for indexing or iteration |
| Performance | E128215 | StringBuilder created without capacity for a known append count |
| Performance | E128226 | Comparer set built by constructor and Add loop |
| Performance | E128229 | Middleware binds the Func<Task> next delegate |
| Performance | E128231 | string.Split result enumerated without a stored array |
| Performance | E128233 | Parallel.For runs one delegate per item |
| Performance | E128235 | Readonly field re-read inside a loop |
| Performance | E128255 | Use TensorPrimitives.Add/Multiply instead of an element-wise loop |
| Security | E128071 | Use an approved cryptographic algorithm |
| Security | E128075 | Use RandomNumberGenerator instead of Random in crypto context |
| Security | E128091 | Use ArgumentList instead of a built Arguments string on ProcessStartInfo |
| Security | E128142 | Do not instantiate a Managed or CNG cryptography type |
| Security | E128146 | Use TLS 1.2 or later |
| Security | E128147 | RNGCryptoServiceProvider is deprecated |
| Security | E128149 | Use the full 16-byte AES-GCM tag |
| Security | E128150 | Do not use SHA-3, SHAKE or KMAC |
| Security | E128156 | HttpClient certificate validation accepts every certificate (default: Error) |
| Security | E128157 | Fixed-time comparison of a secret-derived value |
| Security | E128222 | Path.Combine of a root .FullName and an uncontained leaf |
| Security | E128227 | HTTP body read without a size bound |
| Security | E128242 | Antiforgery missing on a state-changing action |
| Security | E128256 | Local filesystem path passed to a logger call |
| Security | E128263 | Containment test compares a root with no directory separator |
| Security | E128266 | Certificate chain result ignored or policy weakened |
| Security | E128267 | Decompression loop has no output bound |
| Style | E128002 | Use string.Empty instead of "" |
| Style | E128006 | Use Encoding.UTF8 instead of Encoding.Default |
| Style | E128024 | Non-XML-doc comment above method declaration |
| Style | E128025 | Use Path.GetRandomFileName() instead of Guid.NewGuid() in temp paths |
| Style | E128043 | Do not use the null-forgiving operator |
| Style | E128047 | #pragma warning disable without justification comment |
| Style | E128055 | Unbalanced #pragma warning disable without matching restore |
| Style | E128063 | Mid-name underscore in private static member (IDE1006 rename artifact) (default: Error, silent in test code) |
| Style | E128065 | #pragma warning disable with multiple IDs — use one pragma per ID |
| Style | E128094 | #pragma warning disable before file-scoped namespace (default: Error) |
| Testing | E128054 | Class creates temp directory without cleanup interface |
| Testing | E128062 | Test uses outdated ReferenceAssemblies — does not match project TFM |
| Testing | E128073 | Test method missing [Trait("Category", ...)] attribute |
| Testing | E128097 | Comment inside test code |
| Testing | E128107 | Test matches one low-value test condition (off by default) |
| Testing | E128108 | Test matches two or more low-value test conditions (off by default) |
| Maintainability | E128088 | Switch over an enum does not case every member |
| Unsafe | E128112 | Do not reinterpret one type as another with Unsafe.As |
| Unsafe | E128113 | Use the unaligned Unsafe read and write methods |
| Unsafe | E128114 | Index the array instead of bypassing its bounds check |
| Unsafe | E128115 | Do not reinterpret between bool and int |
| Unsafe | E128118 | Do not reinterpret bytes as a non-blittable type |
| Unsafe | E128119 | Use an inline array instead of a fixed-size buffer |
| Unsafe | E128120 | Do not skip local initialization without a measured reason |
| Unsafe | E128139 | Do not move a non-blittable type through an unaligned access |