Deserializing a card twice in .NET fails with ID collision errors
See original GitHub issuePlatform
What platform is your issue or question related to? (Delete other platforms).
- .NET object model
Author or host
Someone deserializing cards (issue was reported by internal MS customer)
Version of SDK
NuGet 1.2.0
Issue
If you use JSON.NET to deserialize a card that’s within another object and then immediately deserialize the same card again, a collision ID occurs… even though it’s deserializing two separate instances.
It seems like the collision ID logic is using a shared static or something when the AdaptiveCard isn’t the top-level thing being deserialized.
Repro code (install latest .NET 1.2.0 from NuGet)
public class cards
{
public AdaptiveCard Card { get; set; }
}
private void Test()
{
string cardsJson = @"{ ""card"": {
""type"": ""AdaptiveCard"",
""version"": ""1.0"",
""body"": [
{
""type"": ""Input.Text"",
""id"": ""myTextInput""
}
]
} }";
cards fullcardresponse = JsonConvert.DeserializeObject<cards>(cardsJson);
// Deserialize again, exception gets thrown here
fullcardresponse = JsonConvert.DeserializeObject<cards>(cardsJson);
}
AdaptiveCards.AdaptiveSerializationException: 'Collision detected for id 'myTextInput''
Workaround
If you use the official AdaptiveCard.FromJson
method, it works fine. This problem is limited to deserializing a JSON object that inside it contains an Adaptive Card. So workaround is that you could parse the initial object and then grab the card as a JObject and then parse that using the official parsing method
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:13 (5 by maintainers)
Top GitHub Comments
I was able to stop this from occurring by setting the Attachment Content as card.ToJson() instead of straight to card
@paulcam206 mind taking a stab at this since you are the id collision guru 😃 thanks!