fix(data): cast null to nullable JsonSerializerOptions in EF value converters (CS8600, 66 findings) #666

Closed
opened 2026-07-17 16:28:00 +00:00 by spikerj · 1 comment
Owner

SpikerDbContexts EF Core HasConversion value converters disambiguate the JsonSerializer.Serialize/Deserialize overload with (JsonSerializerOptions)null — casting the null literal to the non-nullable type. The compiler correctly flags this as CS8600 (66 findings, all in this one file), so it is real noise, not a runtime bug: the options parameter is JsonSerializerOptions? and null is the documented "use default options" value. The cast was only ever an overload selector (options vs. JsonTypeInfo).

Fix: change all 98 casts to (JsonSerializerOptions?)null, matching the 10 sites in this same file already migrated to that form (an in-progress cleanup). Nullability annotations are erased for overload resolution, so the identical overload binds — zero behavior change. This removes the noise at the source rather than suppressing findings that would regenerate on every rescan.

Scope: SpikerSoft.Data/Contexts/SpikerDbContext.cs only. dotnet build SpikerSoft.UnitTests.slnf clean (0 errors); no CS8600 remains in this file. SonarQube rule external_roslyn:CS8600.

Note: one unrelated CS8600 remains in CachedRepository.cs:298 ((RedisValue[])keys — guarded by !keys.IsNull, a different nullable-flow case) and is intentionally left out of this annotation-only PR.

SpikerDbContexts EF Core `HasConversion` value converters disambiguate the `JsonSerializer.Serialize`/`Deserialize` overload with `(JsonSerializerOptions)null` — casting the null literal to the **non-nullable** type. The compiler correctly flags this as CS8600 (66 findings, all in this one file), so it is real noise, not a runtime bug: the `options` parameter is `JsonSerializerOptions?` and `null` is the documented "use default options" value. The cast was only ever an overload selector (options vs. JsonTypeInfo). **Fix:** change all 98 casts to `(JsonSerializerOptions?)null`, matching the **10 sites in this same file already migrated** to that form (an in-progress cleanup). Nullability annotations are erased for overload resolution, so the identical overload binds — zero behavior change. This removes the noise at the source rather than suppressing findings that would regenerate on every rescan. Scope: `SpikerSoft.Data/Contexts/SpikerDbContext.cs` only. `dotnet build SpikerSoft.UnitTests.slnf` clean (0 errors); no CS8600 remains in this file. SonarQube rule external_roslyn:CS8600. Note: one unrelated CS8600 remains in `CachedRepository.cs:298` (`(RedisValue[])keys` — guarded by `!keys.IsNull`, a different nullable-flow case) and is intentionally left out of this annotation-only PR.
Author
Owner

Resolved in spikersoft-backend PR #366 (merged to master by spikerj). Changed all 98 EF value-converter casts in SpikerDbContext to (JsonSerializerOptions?)null; zero behavior change, CS8600 removed at the source. Closing.

Resolved in spikersoft-backend PR #366 (merged to `master` by spikerj). Changed all 98 EF value-converter casts in SpikerDbContext to (JsonSerializerOptions?)null; zero behavior change, CS8600 removed at the source. Closing.
Sign in to join this conversation.