microsoft / microsoft/AdaptiveCards
[Bug] [Templating] [dot Net] `$when` condition doesn't work as expected with `$index` and `$data`
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2k
- Forks
- 595
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 1
Description
Platform
What platform is your issue or question related to? (Delete other platforms).
- .NET 5.0
Author or host
Are you an author (like sending something to Outlook), or a host that is rendering your own cards? If host, please specify the corresponding host (app) name.
- Author
If you're an author, who are you sending cards to?
- Microsoft Teams
Version of SDK
What version are you using? Ex: NuGet 1.0.2, or latest main, etc...
- Dot Net NuGet AdaptiveCards.Templating 1.2.2
Issue
When I call AdaptiveCardTemplate.Expand() to bind data to an AdaptiveCardTemplate, the returned card is missing some elements whose $when condition should be evaluated as True.
In the meantime, the online designer expands that card correctly.
Repro Steps
Code
var cardTemplate = new AdaptiveCardTemplate(templateJsonString);
string expand = cardTemplate.Expand(dataJsonString);
Console.WriteLine($"Contain TextBox: {expand.Contains("Index 1")}");
Sample Template
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.3",
"body": [{
"type": "Container",
"$when": "${$index>0}",
"items": [{
"type": "TextBlock",
"text": "Index ${$index}"
}],
"$data": "${foo}"
}]
}
Sample Data
{
"foo": [1, 1]
}
Expanded Card String
{"$schema":"http://adaptivecards.io/schemas/adaptive-card.json","type":"AdaptiveCard","version":"1.3","body":[]}
Expected behavior
The expanded card should contain a TextBlock, whose text is Index 1. Just as the online designer does.
{"$schema":"http://adaptivecards.io/schemas/adaptive-card.json","type":"AdaptiveCard","version":"1.3","body":[{"type":"Container","items":[{"type":"TextBlock","text":"Index 1"}]}]}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at AdaptiveCardTemplate.Expand() and reproduce the issue with the provided C# code, template, and data. Compare the .NET expansion with the online designer, focusing on how $when is evaluated alongside $index and $data. Done means the expanded card includes the Container and TextBlock with "Index 1" as shown in the expected JSON.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100