Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Bot发送CardImage时出现异常_C#_Asp.net Mvc_Asp.net Web Api_Web_Botframework - Fatal编程技术网

C# 从Bot发送CardImage时出现异常

C# 从Bot发送CardImage时出现异常,c#,asp.net-mvc,asp.net-web-api,web,botframework,C#,Asp.net Mvc,Asp.net Web Api,Web,Botframework,我已经在bot框架中使用LUIS编写了基于意图匹配发送消息的代码。 这是我的密码 [LuisIntent("Skype for Business")] public async Task Skype4Business(IDialogContext context, LuisResult result) { var connector = new ConnectorClient(new Uri(context.Activity.ServiceUrl));

我已经在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);
        }
[Luisinten(“Skype for Business”)]
公共异步任务Skype4Business(IDialogContext上下文,LuisResult结果)
{
var connector=newconnectorclient(新Uri(context.Activity.ServiceUrl));
尝试
{
//将我们的回复返回给用户
List cardImageList=新列表();
列表按钮=新建列表();
CardImage CardImage=new CardImage{Alt=“SpeechPic”,Url=@“C:\Users\Rock\Documents\visualstudio 2015\Projects\Text Analytics\Text Analytics\Resources\Skype-for-business-2.jpg”};
cardImages=新列表();
添加(cardImage);
CardAction skypeButton=新的CardAction()
{
Value=“example.com/”,
Type=“openUrl”,
Title=“Skype for Business”
};
按钮。添加(skypeButton);
HeroCard HeroCard=新的HeroCard()
{
Title=“Skype For Business”,
图像=心脏图像,
按钮=按钮
};
var message=context.MakeMessage();
message.Attachments=新列表();
message.AttachmentLayout=AttachmentLayoutTypes.List;
message.Attachments.Add(heroCard.ToAttachment());
等待上下文。PostAsync(消息);
Wait(MessageReceived);
}
因此,每当我从机器人发送回复时,如果目的匹配,例如:Skype for business。因此,我通过制作卡片并在其中添加cardimage和按钮进行回复。它发送时没有任何错误,但在发送成功后,它也会向我显示异常。

我被困在这里,即使我添加了try/catch子句来处理异常,但我仍然得到了异常。 如何解决这个问题?
任何帮助或指导都将不胜感激。

问题在于您似乎有一个全局变量
cardImages
,因此,您遇到了序列化问题,因为
CardImage
不可序列化

您有两个卡片图像列表:

List<CardImage> cardImageList = new List<CardImage>();

cardImages = new List<CardImage>();
List cardimagerlist=新列表();
cardImages=新列表();

您应该使用在方法范围(
cardImageList
)中创建的图像列表,而不是全局变量。请确保也删除全局变量。

无法复制您的问题。您使用的是最新版本的框架吗?是的,我使用的是最新版本的bot框架