[Fixed] Teams: "error rendering message" in Adaptive Card (Bot Framework) for some SQL content – C#

by
Ali Hasan
c# robotframework teams-toolkit

Quick Fix: At present, there is no direct resolution for this issue. As a temporary workaround, avoid using quotation marks "" in the SQL statement when composing Adaptive Cards.

The Problem:

When rendering an Adaptive Card in Microsoft Teams using the SQL query in a TextBlock component, an error "Error encountered while rendering this message" is encountered. This occurs specifically when using a particular SQL query. The error is not specific and does not provide detailed information about the root cause.

The Solutions:

Solution 1: Workaround solution

The error message "Error encountered while rendering this message" is due to a confirmed bug in Teams, which is being tracked on GitHub (https://github.com/MicrosoftDocs/msteams-docs/issues/9392). Until the bug is fixed, you can use the following workaround:

  • Wrap the assignment of the sql variable in WebUtility.HtmlEncode(sql). This will fix the issue.

  • Example:

var cardContent = new AdaptiveCardTemplate(cardTemplate).Expand(
			new
			{
				Query = WebUtility.HtmlEncode(sql)
			}
		);
  • With this workaround, the SQL query will be properly encoded and the card will render correctly in Teams.

Q&A

What is causing the error in the Adaptive Card?

It is a confirmed bug and tracked here: https://github.com/MicrosoftDocs/msteams-docs/issues/9392

What is a workaround?

It can be fixed by wrapping the assignment into WebUtility.HtmlEncode(sql).

Video Explanation:

The following video, titled "Fix It to the Finish Line | Super Bowl LVIII Part Three | Defending the ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

5 days ago ... Voice of the Chiefs Mitch Holthus and senior team reporter Matt McMullen bring you another episode of Defending The Kingdom from Las Vegas, ...