AdaptiveCards icon indicating copy to clipboard operation
AdaptiveCards copied to clipboard

Adaptive cards not working with latest nuget update in .Net

Open mkauroaktreecapital opened this issue 10 months ago • 9 comments

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<Years>() }; 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; }

mkauroaktreecapital avatar Feb 21 '25 11:02 mkauroaktreecapital

@mkauroaktreecapital - Could you please share a video of the error that you're getting. Could you please confirm if you are facing this issue even when the card is sent through Developer portal.

Meghana-MSFT avatar Feb 24 '25 07:02 Meghana-MSFT

@Meghana-MSFT Does this bug fall to Teams? I am not able to repro on our visualizer; however, I'd need more information on the CalendarMeetingInfo object for a full repro.

anna-dingler avatar Feb 24 '25 19:02 anna-dingler

@anna-dingler - Question author mentioned Microsoft Teams in Application name, however I tried to send the card through developer portal in Teams and it worked. @mkauroaktreecapital - Could you please share above asked details to @anna-dingler.

Meghana-MSFT avatar Feb 25 '25 06:02 Meghana-MSFT

@mkauroaktreecapital - Could you please share a video of the error that you're getting. Could you please confirm if you are facing this issue even when the card is sent through Developer portal.

Yes, we are getting this issue from developer portal as well. Card is not rendering if I paste the cardJson which is created through code after template.Expand(). And we can see formatDateTime function not expanding properly due to which error occurs.

Image

mkauroaktreecapital avatar Feb 25 '25 10:02 mkauroaktreecapital

@anna-dingler - Question author mentioned Microsoft Teams in Application name, however I tried to send the card through developer portal in Teams and it worked. @mkauroaktreecapital - Could you please share above asked details to @anna-dingler.

Sample CalendarMeetingInfo object json that is used to fill data in card is below: {"AttendeeList":null,"TimeSlotList":null,"CalendarDetails":null,"MinimumAttendeePercentage":0.0,"MeetingDuration":null,"SelectedDuration":null,"StartDateTime":null,"EndDateTime":null,"Subject":null,"Description":null,"Attendees":null,"Calendar":null,"Year":"","EventFrequency":null,"BusinessDay":null,"OtherDay":"","StartTime":"2025-02-25T17:35:08.2842369","EndTime":"2025-02-25T17:35:08.2842369","YearList":[{"Year":"2025"},{"Year":"2026"}],"submitCard":null,"QuarterlyFrequency":null,"QuarterlyOther":null,"MonthlyFrequency":null,"MonthlyOther":null,"ReturnDueToInvalidData":false,"usersMailIds":null,"CalendarID":null,"ScheduledID":0,"Delivered":false}

string cardJson = template.Expand(meetingInfoState);

In cardJson that we get after expanding the template we can see formatDateTime function as is, which is wrong. It should be able to read the startTime and convert it to HH:mm and then assign its value. This works fine with older nuget versions. Issue is with new version.

Works fine with adaptive cards designer. Image

mkauroaktreecapital avatar Feb 25 '25 12:02 mkauroaktreecapital

@jwoo-msft FYI it does look like this repros with .NET templating

anna-dingler avatar Mar 04 '25 18:03 anna-dingler

@mkauroaktreecapital - Hi, I just came across this thread. Are you still encountering this issue?

Nivedipa-MSFT avatar Nov 27 '25 09:11 Nivedipa-MSFT

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

Ashrafn672 avatar Nov 27 '25 17:11 Ashrafn672