Skip to content

Adaptive cards not working with latest nuget update in .Net #9117

@mkauroaktreecapital

Description

@mkauroaktreecapital

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;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions