microsoft / microsoft/AdaptiveCards

Json deserialization of AdaptiveRichTextBlock fails

Open
#8,494 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
2k
Forks
595
Avg merge
1d 19h
Merged PRs (30d)
1

Description

Platform

  • .NET

Version of SDK

latest (NuGet 3.0.0)

Issue

When I deserialize an AdaptiveRichTextBlock from Json the Inlines attribute is expected to by a Json array but the serializer creates an object.
I observed this in Botframework v4 when using an AdaptiveRichTextBlock in a prompt. When the user sends a response to the prompt the Botframework is unable to restore the context due to this issue.

Steps to Reproduce

using AdaptiveCards;
using Newtonsoft.Json;

var s = JsonConvert.SerializeObject(new AdaptiveRichTextBlock
{
  Inlines = new List<AdaptiveInline>
  {
    new AdaptiveTextRun
    {
      Text = "test"
    }
  }
}, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All });
var o = JsonConvert.DeserializeObject<AdaptiveRichTextBlock>(s);

The AdaptiveRichTextBlock is serialized to

{
  "$type": "AdaptiveCards.AdaptiveRichTextBlock, AdaptiveCards",
  "type": "RichTextBlock",
  "inlines": {
    "$type": "System.Collections.Generic.List`1[[AdaptiveCards.AdaptiveInline, AdaptiveCards]], System.Private.CoreLib",
    "$values": [
      {
        "$type": "AdaptiveCards.AdaptiveTextRun, AdaptiveCards",
        "type": "TextRun",
        "text": "test"
      }
    ]
  }
}

but the deserializer expects

{
  "$type": "AdaptiveCards.AdaptiveRichTextBlock, AdaptiveCards",
  "type": "RichTextBlock",
  "inlines": [
    {
      "$type": "AdaptiveCards.AdaptiveTextRun, AdaptiveCards",
      "type": "TextRun",
      "text": "test"
    }
  ]
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided C# reproduction with AdaptiveRichTextBlock, Newtonsoft.Json, and TypeNameHandling.All. Inspect the AdaptiveRichTextBlock serialization and deserialization path; done means the round trip succeeds and produces the expected inlines array shape without breaking polymorphic inline types.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.