microsoft / microsoft/AdaptiveCards
Adaptive cards not working with latest nuget update in .Net
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2k
- Forks
- 595
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 1
Description
Target Platforms
Other
SDK Version
AdaptiveCards=3.1.0
AdaptiveCards.Templating=2.0.4
Application Name
Microsoft Teams and Bot Emulator
Problem Description
Adaptive cards started throwing exceptions with latest nuget in .Net in emulator and teams channel. It works fine with previous version of nugets, but with latest it gives error.
Old version (working fine):
AdaptiveCards=2.7.1
AdaptiveCards.Templating=1.2.1
Latest version (Throwing error for same cards)
AdaptiveCards=3.1.0
AdaptiveCards.Templating=2.0.4
There are multiple cards failing because of this.
Screenshots
No response
Card JSON
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Schedule",
"wrap": true,
"color": "Light",
"horizontalAlignment": "left",
"size": "Medium"
}
],
"backgroundImage": {
"url": "https://xxxx.blob.core.windows.net/abcdef/abcg.png",
"fillMode": "Repeat"
}
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "Input.ChoiceSet",
"id": "Year",
"style": "expanded",
"value": "${Year}",
"label": "Select Year",
"isRequired": true,
"isMultiSelect": false,
"errorMessage": "Year is required.",
"choices": [
{
"$data": "${YearList}",
"title": "${year}",
"value": "${year}"
}
]
}
]
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "Input.Time",
"id": "startTime",
"isRequired": true,
"value": "${formatDateTime(startTime, 'HH:mm')}",
"errorMessage": "Time is required and cannot be blank.",
"label": "Start Time(in your time zone)"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "Input.Time",
"id": "endTime",
"isRequired": true,
"value": "${formatDateTime(endTime, 'HH:mm')}",
"errorMessage": "Time is required and cannot be blank.",
"label": "End Time(in your time zone)"
}
]
}
]
},
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Frequency"
}
]
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Monthly",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "Input.ChoiceSet",
"id": "MonthlyFrequency",
"style": "expanded",
"label": "Select business day of the month for the event",
"isRequired": true,
"errorMessage": "Select business day of the month for the event",
"choices": [
{
"title": "First",
"value": "First"
},
{
"title": "Last",
"value": "Last"
},
{
"title": "Other",
"value": "Other"
}
]
},
{
"type": "Input.Number",
"id": "MonthlyOther",
"placeholder": "Number must be between 2-20",
"value": "${OtherDay}",
"errorMessage": "If you have selected Other, number must be between 2-20",
"label": "If you have selected Other, which business day of the month you want to add an event?"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK",
"data": {
"submitCard": "Monthly"
}
},
{
"type": "Action.Submit",
"title": "Cancel",
"data": {
"submitCard": "cancel"
},
"associatedInputs": "none"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
},
{
"type": "Action.ShowCard",
"title": "Quarterly",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "Input.ChoiceSet",
"id": "QuarterlyFrequency",
"style": "expanded",
"label": "Select business day of the quarter for the event",
"isRequired": true,
"errorMessage": "Select business day of the quarter for the event",
"choices": [
{
"title": "First",
"value": "First"
},
{
"title": "Last",
"value": "Last"
},
{
"title": "Other",
"value": "Other"
}
]
},
{
"type": "Input.Number",
"id": "QuarterlyOther",
"placeholder": "Number must be between 2-62",
"value": "${OtherDay}",
"errorMessage": "If you have selected Other, number must be between 2-62",
"label": "If you have selected Other, which business day of the quarter you want to add an event?"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK",
"data": {
"submitCard": "Quarterly"
}
},
{
"type": "Action.Submit",
"title": "Cancel",
"data": {
"submitCard": "cancel"
},
"associatedInputs": "none"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
}
]
}
Sample Code Language
.NET
Sample Code
try
{
var card = "EventScheduleDirectLine.json";
if (isMsTeamsChannel)
{
card = "EventSchedule.json";
}
var fileRead = System.IO.File.ReadAllText(Path.Combine(".", "Cards", card));
AdaptiveCardTemplate template = new AdaptiveCardTemplate(fileRead);
meetingInfoState = new CalendarMeetingInfo { YearList = new List() };
for (int i = DateTime.Now.Year; i <= DateTime.Now.Year + 1; i++)
{
int counter = 1;
meetingInfoState.YearList.Add(new Years
{
Year = i.ToString()
});
counter++;
}
meetingInfoState.Year = "";
var currentDateTime = Helper.ConvertToUtcToLocalTime(DateTime.Now, userProfile.Timezone);
if (meetingInfoState.StartTime == new DateTime())
{
meetingInfoState.StartTime = currentDateTime;
}
if (meetingInfoState.EndTime == new DateTime())
{
meetingInfoState.EndTime = currentDateTime;
}
meetingInfoState.OtherDay = "";
string cardJson = template.Expand(meetingInfoState);
var adaptiveCardAttachment = new Microsoft.Bot.Schema.Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(cardJson),
};
return adaptiveCardAttachment;
}
catch (Exception ex)
{
return null;
}
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
Reproduce the failure with the supplied card JSON and sample .NET code using AdaptiveCards 3.1.0 and AdaptiveCards.Templating 2.0.4, then compare with versions 2.7.1 and 1.2.1. Identify the exception and affected template or card element; done means the cards expand successfully in the emulator and Teams channel without regression.
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
- Needs clarification
- Newbie friendliness
- 25/100