Nalix.Analyzers Code Fixes

Read time 3 minutes Package: Nalix.Analyzers
On this page

Nalix.Analyzers.CodeFixes provides 16 Roslyn CodeFixProvider classes that automate common mechanical fixes for 20 active diagnostic IDs (plus retired NALIX031) emitted by Nalix.Analyzers.

Source Mapping

All providers live under analyzers/Nalix.Analyzers.CodeFixes/:

Provider ClassFixed DiagnosticsCode Fix Action TitleTransformation
PacketOpcodeCodeFixProviderNALIX002Add [PacketOpcode]Adds [PacketOpcode(0x0000)] to a handler method inside a [PacketHandler] controller.
PacketHandlerCodeFixProviderNALIX008Add [PacketHandler]Adds [PacketHandler] to the containing controller class.
PacketRegistryDeserializerCodeFixProviderNALIX009Implement IPacketDeserializer<T>Adds IPacketDeserializer<ClassName> to the base list and generates public static new ClassName Deserialize(ReadOnlySpan<byte> buffer) => PacketBase<ClassName>.Deserialize(buffer);.
PacketSelfTypeCodeFixProviderNALIX010, NALIX011Use '{ClassName}' as type argumentReplaces the wrong generic type argument in PacketBase<TSelf> or IPacketDeserializer<T> with the containing class name.
PacketDeserializeCodeFixProviderNALIX012, NALIX052Generate valid static Deserialize methodAdds or updates Deserialize to public static new ClassName Deserialize(ReadOnlySpan<byte> buffer) => PacketBase<ClassName>.Deserialize(buffer);.
SerializeOrderMissingCodeFixProviderNALIX013Add [SerializeOrder] / Add [SerializeIgnore]Offers two actions: adds [SerializeOrder(nextOrder)] (using maxOrder + 1 on the type) or adds [SerializeIgnore].
DuplicateSerializeOrderCodeFixProviderNALIX014Use next available SerializeOrderUpdates the duplicate [SerializeOrder] argument to maxOrder + 1.
SerializationConflictCodeFixProviderNALIX015Remove [SerializeOrder] / Remove [SerializeIgnore]Offers two actions to remove either [SerializeOrder] or [SerializeIgnore] when both are present on the same member.
ResetForPoolCodeFixProviderNALIX020Call base.ResetForPool()Inserts base.ResetForPool(); as the first statement of the ResetForPool() override (converting expression-bodied methods to block bodies if needed).
ConfigurationIgnoreCodeFixProviderNALIX023, NALIX024Add [ConfiguredIgnore]Adds [ConfiguredIgnore] to unsupported (NALIX023) or non-bindable (NALIX024) properties on ConfigurationLoader subclasses.
MiddlewareCodeFixProviderNALIX030, NALIX032Add [MiddlewareOrder(0)] (NALIX030) / Remove AlwaysExecute (NALIX032)Adds [MiddlewareOrder(0)] to a middleware class (NALIX030) or removes AlwaysExecute = true on MiddlewareStage.Inbound (NALIX032, plus retired NALIX031).
DispatchLoopCountCodeFixProviderNALIX047Clamp dispatch loop count to 1..64Clamps out-of-range integer literals passed to WithDispatchLoopCount(...) into the valid 1..64 range (< 1 becomes 1, > 64 becomes 64).
RedundantPacketCastCodeFixProviderNALIX055Remove redundant Packet castReplaces (MyPacket)context.Packet or context.Packet as MyPacket with context.Packet.
NullMiddlewareCodeFixProviderNALIX056Remove null middleware registrationRemoves the .WithMiddleware(null) / .WithErrorHandlingMiddleware(null) invocation from the fluent builder chain.
RequestOptionsConsistencyCodeFixProviderNALIX057Set TimeoutMs to 5000 / Disable retriesResolves infinite-timeout + retry conflicts (NALIX057) by either setting TimeoutMs = 5000 or setting RetryCount = 0.
GenericPacketHandlerCodeFixProviderNALIX058Remove [PacketOpcode]Removes [PacketOpcode] from generic methods that cannot be bound as packet handlers.

When Diagnostics Do Not Have a Code Fix

Diagnostics that require an explicit architectural or security decision intentionally do not provide an automated code fix:

  • Duplicate opcodes (NALIX001, NALIX036, NALIX068, NALIX106) and reserved opcodes (NALIX035): Opcode numbers are wire-protocol contracts shared between client and server; picking a random opcode automatically would break wire compatibility.
  • Handler signature & scope violations (NALIX003, NALIX067, NALIX076): Require deciding whether to resolve a service via [FromScope] or copy data before offloading work.
  • RPC contract & resource rules (NALIX039, NALIX075, NALIX100–NALIX104, NALIX107): Require choosing the right RPC return/parameter contract, removing readonly from [Inject] fields, or resetting mutable fields in ResetForPool().