我已经编写了在bot框架中使用LUIS发送基于意图匹配的消息的代码。这是我的代码。
[LuisIntent("Skype for Business")]
public async Task Skype4Business(IDialogContext context, LuisResult result)
{
var connector = new ConnectorClient(new Uri(context.Activity.ServiceUrl));
try
{
// return our reply to the user
List<CardImage> cardImageList = new List<CardImage>();
List<CardAction> buttons = new List<CardAction>();
CardImage cardImage = new CardImage { Alt = "SpeechPic", Url = @"C:\Users\Rock\Documents\Visual Studio 2015\Projects\Text Analytics\Text Analytics\Resources\Skype-for-business-2.jpg" };
cardImages = new List<CardImage>();
cardImages.Add(cardImage);
CardAction skypeButton = new CardAction()
{
Value = "example.com/",
Type = "openUrl",
Title = "Skype for Business"
};
buttons.Add(skypeButton);
HeroCard heroCard = new HeroCard()
{
Title = "Skype For Business",
Images = cardImages,
Buttons = buttons
};
var message = context.MakeMessage();
message.Attachments = new List<Attachment>();
message.AttachmentLayout = AttachmentLayoutTypes.List;
message.Attachments.Add(heroCard.ToAttachment());
await context.PostAsync(message);
context.Wait(MessageReceived);
}因此,每当我发送来自机器人的回复,如果意图匹配,例如: Skype for business。所以我的回答是制作卡片,并在其中添加心电和按钮。它发送时没有任何错误,但在成功发送后,它也向我显示了异常。

我被困在这里,即使我添加了try/catch子句来处理异常,但我仍然得到了异常。如何解决这个问题?任何帮助或指导都将不胜感激。
发布于 2017-04-27 18:47:27
问题是你似乎有一个全局变量cardImages,因此,你遇到了序列化问题,因为CardImage是不可序列化的。
您有两个卡片图像列表:
List<CardImage> cardImageList = new List<CardImage>();
cardImages = new List<CardImage>();您应该使用在方法作用域(cardImageList)中创建的图像列表,而不是全局变量。确保同时删除全局变量。
https://stackoverflow.com/questions/43652599
复制相似问题