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

CategoryRuleTitle
DesignE128001Use FileInfo/DirectoryInfo instead of string paths
DesignE128003Use TimeProvider instead of DateTime.Now / DateTimeOffset.Now
DesignE128004Use IHttpClientFactory instead of new HttpClient()
DesignE128005Seal classes that have no subclasses
DesignE128007Avoid async void methods (non-event-handler)
DesignE128008Avoid sync-over-async (.Result / .GetAwaiter().GetResult())
DesignE128017Use primary constructor parameter directly
DesignE128019Do not pass CancellationToken by in reference
DesignE128021Do not use in modifier with ref struct parameters (default: Error)
DesignE128030Do not compare FileSystemInfo types by reference (default: Info)
DesignE128032Concrete-only DI registration with available interface
DesignE128036Task.Run wrapping async lambda — unnecessary thread pool hop
DesignE128042Convert.ToInt32/ToInt64 wrapping ExecuteScalar without null guard
DesignE128044Type implements IAsyncDisposable but not IDisposable
DesignE128048Use switch instead of if/else-if chain on enum values
DesignE128049Avoid [DynamicallyAccessedMembers] — suppress with justification if required
DesignE128050Use TimeSpan for time-duration values to avoid unit ambiguity (default: Error)
DesignE128052Use immutable collection interface instead of mutable concrete type (default: Info)
DesignE128053Use collection of FileInfo/DirectoryInfo instead of collection of string for file system paths
DesignE128058Return List<T> via .AsReadOnly() when exposing as IReadOnlyList<T>
DesignE128059Interface method parameter is unused in implementation (default: Error)
DesignE128060Return Dictionary<K,V> via .AsReadOnly() when exposing as IReadOnlyDictionary<K,V>
DesignE128061Use an immutable type for static readonly arrays
DesignE128074Readonly struct property should use init accessor
DesignE128080Use ByteSize for data-size values to avoid unit ambiguity (default: Error)
DesignE128082Do not unwrap ByteSize via cast
DesignE128087Static numeric field should not be incremented with ++/--
DesignE128219Memberless abstract base with all derivation in one assembly should be closed
DesignE128220Union switch ends in a discard or var arm instead of a null arm
DesignE128225Abstract base with members is a closed hierarchy
ReliabilityE128011[GeneratedRegex] missing matchTimeoutMilliseconds
ReliabilityE128012RegexOptions.Compiled is redundant in [GeneratedRegex]
ReliabilityE128013[GeneratedRegex] pattern has repeated wildcards
ReliabilityE128014[GeneratedRegex] pattern has a repeated group that can split across iterations
ReliabilityE128016DateTime.Parse/ParseExact missing DateTimeStyles parameter
ReliabilityE128020Do not use in modifier with mutable structs
ReliabilityE128023Avoid hardcoded /tmp path
ReliabilityE128028Task.FromResult wraps sync I/O that has an async alternative
ReliabilityE128031AddSingleton factory returns IDisposable
ReliabilityE128033Options class bound via .Bind() has init-only property
ReliabilityE128034Constructor news a DI-registered type — inject via DI instead
ReliabilityE128035Concrete-type DI dependency without direct registration
ReliabilityE128037Unbounded Task.WhenAll over async Select or a Task.Run list
ReliabilityE128038Task.WhenAll async lambda missing CancellationToken propagation
ReliabilityE128039Catch filter must exclude OperationCanceledException
ReliabilityE128040Concurrency limit must be positive
ReliabilityE128041JsonDocument.RootElement must not escape the document’s using scope
ReliabilityE128051Broad catch in async HttpClient method missing OperationCanceledException handler
ReliabilityE128056File existence check TOCTOU race condition
ReliabilityE128057Unprotected cleanup in finally block
ReliabilityE128064Disk write-then-read round-trip — use the in-memory value instead of reading back
ReliabilityE128070Pool Rent() capacity must be bounded — guard with Math.Min
ReliabilityE128076Materialize QuerySelectorAll result before iterating
ReliabilityE128077TextContent string match requires a preceding length guard
ReliabilityE128086ArrayPool buffer used as SqliteParameter value without Size
ReliabilityE128092Use async File.*Async overload instead of sync method
ReliabilityE128093Use async DbConnection/DbCommand *Async overload instead of sync method
ReliabilityE128096Detect synchronous call to async local function via .Result or .Wait()
ReliabilityE128099Wait for process exit with a provable timeout
ReliabilityE128100Catch filter reads negated token state on OperationCanceledException
ReliabilityE128101Verify process output file exists before use
ReliabilityE128109stackalloc must be bounded and outside loops
ReliabilityE128110Zero a pooled buffer in a finally block before Return
ReliabilityE128155Mutating the loop source inside its own foreach
ReliabilityE128159TaskCompletionSource without RunContinuationsAsynchronously
ReliabilityE128161Path.Combine with a rooted or parent segment
ReliabilityE128163ImmutableArray field left at its default
ReliabilityE128172catch swallows an assertion failure
ReliabilityE128175SemaphoreSlim wait with no finally release guarantee
ReliabilityE128176Event subscription that keeps the subscriber alive
ReliabilityE128179Options type bound from configuration with no validation call
ReliabilityE128189GCHandle with no Free call
ReliabilityE128190FileStream created without asynchronous I/O
ReliabilityE128194Lazy<T> field without thread safety
ReliabilityE128238Array comparison uses reference equality, not element equality
ReliabilityE128250Private field assignment overwritten before a read
ReliabilityE128269Declaration syntax read without a syntax tree check
ReliabilityE128270Rented pooled buffer is never returned
PerformanceE128009Use MinBy/MaxBy instead of OrderBy().First()
PerformanceE128010Pass HttpCompletionOption.ResponseHeadersRead to HttpClient calls
PerformanceE128015Use string interpolation instead of string.Format
PerformanceE128018Use ToArray() instead of ToList() for read-only foreach
PerformanceE128026Redundant HashSet allocation in FrozenSet creation
PerformanceE128027Use FrozenSet/FrozenDictionary for static readonly collections
PerformanceE128029Replace multi-string OR-chain with HashSet.Contains
PerformanceE128066Linear lookup inside loop creates O(n²) complexity
PerformanceE128067String concatenation in loop creates O(n²) allocations
PerformanceE128068Sort operation inside loop creates O(n² log n) complexity
PerformanceE128072Prefer SHA256.HashData() over SHA256.Create() (default: Info)
PerformanceE128081Use StringBuilderPool instead of new StringBuilder() (default: Info)
PerformanceE128083Use ImmutableCollectionsMarshal.AsImmutableArray instead of ImmutableArray.Create/CreateRange with ToArray
PerformanceE128084Use CollectionsMarshal.AsSpan instead of List.GetRange or a list indexer loop
PerformanceE128085Use foreach + AddRange instead of SelectMany.ToList
PerformanceE128098Collapse chained or looped string.Replace calls into a single pass
PerformanceE128102Use SearchValues<char> for IndexOfAny scans
PerformanceE128116Do not use MethodImplOptions.AggressiveOptimization
PerformanceE128117Use LibraryImport instead of DllImport
PerformanceE128121Use SequenceEqual instead of an element-by-element loop
PerformanceE128122Guard an expensive log argument with IsEnabled
PerformanceE128123Use [GeneratedRegex] for a constant pattern
PerformanceE128124Cache SearchValues in a static readonly field
PerformanceE128131Parse UTF-8 bytes with the span overload instead of a decoded string
PerformanceE128132Do not use a culture-aware comparer for a collection key
PerformanceE128133Use an alternate lookup instead of a temporary string key
PerformanceE128134Use BitOperations.PopCount instead of a shift loop
PerformanceE128135Use TensorPrimitives instead of a sum, min, or max loop
PerformanceE128140Use Span.Fill/Clear/CopyTo instead of an element loop
PerformanceE128141Use a u8 literal instead of Encoding.UTF8.GetBytes
PerformanceE128152Complexity past the e128_max_complexity ceiling (nested loops, recursion)
PerformanceE128205Collection filled in a loop has a known final count
PerformanceE128207Reflection lookup inside a loop
PerformanceE128208ContainsKey then indexer on a ConcurrentDictionary
PerformanceE128209GetBytes(...).Length inside a loop allocates a byte array for its length
PerformanceE128210new Regex inside a loop with a loop-invariant pattern
PerformanceE128212ToCharArray result used only for indexing or iteration
PerformanceE128215StringBuilder created without capacity for a known append count
PerformanceE128226Comparer set built by constructor and Add loop
PerformanceE128229Middleware binds the Func<Task> next delegate
PerformanceE128231string.Split result enumerated without a stored array
PerformanceE128233Parallel.For runs one delegate per item
PerformanceE128235Readonly field re-read inside a loop
PerformanceE128255Use TensorPrimitives.Add/Multiply instead of an element-wise loop
SecurityE128071Use an approved cryptographic algorithm
SecurityE128075Use RandomNumberGenerator instead of Random in crypto context
SecurityE128091Use ArgumentList instead of a built Arguments string on ProcessStartInfo
SecurityE128142Do not instantiate a Managed or CNG cryptography type
SecurityE128146Use TLS 1.2 or later
SecurityE128147RNGCryptoServiceProvider is deprecated
SecurityE128149Use the full 16-byte AES-GCM tag
SecurityE128150Do not use SHA-3, SHAKE or KMAC
SecurityE128156HttpClient certificate validation accepts every certificate (default: Error)
SecurityE128157Fixed-time comparison of a secret-derived value
SecurityE128222Path.Combine of a root .FullName and an uncontained leaf
SecurityE128227HTTP body read without a size bound
SecurityE128242Antiforgery missing on a state-changing action
SecurityE128256Local filesystem path passed to a logger call
SecurityE128263Containment test compares a root with no directory separator
SecurityE128266Certificate chain result ignored or policy weakened
SecurityE128267Decompression loop has no output bound
StyleE128002Use string.Empty instead of ""
StyleE128006Use Encoding.UTF8 instead of Encoding.Default
StyleE128024Non-XML-doc comment above method declaration
StyleE128025Use Path.GetRandomFileName() instead of Guid.NewGuid() in temp paths
StyleE128043Do not use the null-forgiving operator
StyleE128047#pragma warning disable without justification comment
StyleE128055Unbalanced #pragma warning disable without matching restore
StyleE128063Mid-name underscore in private static member (IDE1006 rename artifact) (default: Error, silent in test code)
StyleE128065#pragma warning disable with multiple IDs — use one pragma per ID
StyleE128094#pragma warning disable before file-scoped namespace (default: Error)
TestingE128054Class creates temp directory without cleanup interface
TestingE128062Test uses outdated ReferenceAssemblies — does not match project TFM
TestingE128073Test method missing [Trait("Category", ...)] attribute
TestingE128097Comment inside test code
TestingE128107Test matches one low-value test condition (off by default)
TestingE128108Test matches two or more low-value test conditions (off by default)
MaintainabilityE128088Switch over an enum does not case every member
UnsafeE128112Do not reinterpret one type as another with Unsafe.As
UnsafeE128113Use the unaligned Unsafe read and write methods
UnsafeE128114Index the array instead of bypassing its bounds check
UnsafeE128115Do not reinterpret between bool and int
UnsafeE128118Do not reinterpret bytes as a non-blittable type
UnsafeE128119Use an inline array instead of a fixed-size buffer
UnsafeE128120Do not skip local initialization without a measured reason
UnsafeE128139Do not move a non-blittable type through an unaligned access