Skip to content

A range, range set or value set declared as its factory or operations interface is written as {} in JSON #579

Done

Description

@CaffeinatedCoder

Found by a pre-release sweep of main @ 577b85e (lens: framework-heuristics); reproduced in a scratch test.

Problem

A property declared as IRangeSetOperations<TSet> or IRangeSetFactory<TSet, TRange, T> is written as {} by System.Text.Json, with no error. The value is lost on write, and reading {} back throws NotSupportedException.

AGENTS.md: "The range and set interfaces carry InterfaceDeclaredJsonConverter (write through the runtime type, refuse a read) … so a value's wire form never depends on how it was declared." IRangeSet<,>, IRangeSetProducer<,,>, IRange<T> and IValueSet<T> carry it. These do not:

  • IRangeSetOperations<TSet> (src/CodoMetis.ValueRanges/Core/IRangeSetOperations.cs:15), new in 11.0.0
  • IRangeSetFactory<TSet, TRange, T> (Core/IRangeSetFactory.cs:18), new in 11.0.0
  • IRangeFactory<TRange, T> (Core/IRangeFactory.cs:29), also on 10.x
  • IValueSetFactory<TSet, T> (Core/IValueSetFactory.cs:19), also on 10.x

The convention test leaves them out on purpose. JsonDefaultContractTests.DeclarableInterfacesOf (test/CodoMetis.ValueRanges.Conventions.Tests/JsonDefaultContractTests.cs:208) skips every interface with a static abstract member, "whose static abstract members rule them out as a declared type". They rule it out as a type argument only (CS8920). A property, a field or a record parameter of such a type compiles.

Scenario

public sealed record A(IRangeSetOperations<DateRangeSet> V);
public sealed record B(IRangeSetFactory<DateRangeSet, DateRange, DateOnly> V);
public sealed record C(IRangeFactory<DateRange, DateOnly> V);
public sealed record D(IValueSetFactory<StringSet, string> V);

Measured on 577b85e, JsonSerializer.Serialize with nothing registered:

IRangeSetOperations: {"V":{}}
IRangeSetFactory:    {"V":{}}
IRangeFactory:       {"V":{}}
IValueSetFactory:    {"V":{}}
IRangeSetProducer:   {"V":"[2026-03-01,2026-03-05]"}
IRangeSet:           {"V":"{[2026-03-01,2026-03-05]}"}

It needs a declaration typed as one of these interfaces outside generic code. A DTO generic over TSet closes to the set type and is written correctly.

Change

Put [JsonConverter(typeof(InterfaceDeclaredJsonConverter))] on the four interfaces, and drop the static-abstract exclusion from DeclarableInterfacesOf, so a new interface without the attribute fails there. Check the Native AOT consumer in the smoke test afterwards, since the attribute lands on interfaces with static abstract members.

IRangeFactory<,> and IValueSetFactory<,> have the same gap on release/10.x. That half is a silent fix on a released line, so it ships there as a minor with a ### Changed answers row: a port issue under #521.

Test

JsonDefaultContractTests with the exclusion removed: every interface in the core namespace that a range, a range set or a value set implements writes the literal when a property is declared as it. It fails with the attributes removed.

Activity

  1. added this to the 11.0.0 milestone on Nov 29, 2026
  2. added
    bug
    silent
    area/json
    package/core
    severity/medium
    on Nov 29, 2026
  3. added a commit that references this issue on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/jsonbugpackage/coreseverity/mediumsilent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions