8000 [BUG] "InvalidOperationException: Should not get here" when serializing a nested dictionary using System.Text.Json · Issue #1087 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[BUG] "InvalidOperationException: Should not get here" when serializing a nested dictionary using System.Text.Json #1087
Closed
@Velorien

Description

@Velorien

Steps To Reproduce

Consider the following code:

static async Task Main(string[] args)
{
    var http = new HttpClient();
    http.BaseAddress = new System.Uri("http://localhost:5000");
    var api = RestService.For<IDictionaryTestApi>(http, new RefitSettings
    {
        // uncomment this line and it works:
        // ContentSerializer = new NewtonsoftJsonContentSerializer()
    });

    var body = new Dictionary<string, Dictionary<string, object>>
    {
        { "outerKey", new Dictionary<string, object>
            {
                { "innerKey", "innerString" },
                { "innerKey2", new object() },
                { "innerKey3", new { someProperty = "some value", otherProperty = 42 } }
            }
        }
    };

    // serializes fine
    var bodyJson = System.Text.Json.JsonSerializer.Serialize(body);
    // deserializes fine
    var bodyPoco = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, object>>>(bodyJson);

    // the api definition is as follows:
    // [Post("/DictionaryTest/objectsDictionary")]
    // Task<Dictionary<string, Dictionary<string, object>>> ObjectsDictionary([Body] Dictionary<string, Dictionary<string, object>> body);
    var response = await api.ObjectsDictionary(body); // crashes here

    Print(response); // Omitted
}

It works when I switch to Newtonsoft.Json (also version 6.0.21). The test api used in the example simply echoes what's thrown at it.

Expected behavior

It should not throw an exception.

Screenshots
image

Environment

  • OS: Windows 10 Pro x64 Version 2004
  • Device: not relevant
  • Version: Refit 6.0.21 on .NET SDK 5.0.103
  • Working Version: Refit 5.2.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0