Skip to content

UI test on Revit 2025 serializes a polymorphic record as an empty object #139

Closed

Description

@Nice3point

A RevitApiUiTest on Revit 2025 serializes a polymorphic record with the System.Text.Json package of the project.

On Revit 2025, a library that references the System.Text.Json of the runtime and a library with the System.Text.Json 10.0 package bind two copies of the assembly.
The polymorphism attributes of the first library are then types the serializer of the second library does not read.

Steps to reproduce

  1. Declare an abstract record in a net8.0 library with no package reference to System.Text.Json:

    [JsonPolymorphic(TypeDiscriminatorPropertyName = "kind")]
    [JsonDerivedType(typeof(Overload), "overload")]
    public abstract record Warning;
    
    public sealed record Overload : Warning
    {
        public required double Limit { get; init; }
    }
  2. Serialize a Warning[] with a source-generated JsonSerializerContext in a second library that references the System.Text.Json 10.0.x package and the first library.

  3. Call it from a RevitApiUiTest in Revit 2025.

✔️ Expected Behavior

The array serializes as [{"kind":"overload","limit":1}], and the JSON deserializes back into the array.

❌ Actual Behavior

The array serializes as [{}], and its deserialization throws NotSupportedException: Deserialization of interface or abstract types is not supported.

Environment: Revit 2025.4, .NET 8.0.32, Nice3point.TUnit.Revit 2025.1.9. Revit 2027 on .NET 10 is not affected.
The cause is in the load context of Nice3point.Revit.Injector: https://github.com/Nice3point/RevitInjector/issues/105.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛An unexpected issue that highlights incorrect behaviortests 🧪Test projects

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions