WebClient.DownloadData在Bot Framework中引发异常 [英] WebClient.DownloadData throws an exception in Bot Framework

查看:128
本文介绍了WebClient.DownloadData在Bot Framework中引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上传图像,并使用WebClient和DownloadData来获取字节数组,但现在它引发了异常:

I am uploading an image and using WebClient with DownloadData to get the byte array, but now it throws me an exception:

Exception: State size exceeded configured limit.
[File of type 'text/plain']

我没有注意到这种行为之前具有完全相同的图像。可能出了什么问题?

I haven't noticed such behaviour before with the exact same image. What might have gone wrong?

private async Task SendPhoto_ActivityReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        Activity activity = await result as Activity;
        Activity activityReply = activity.CreateReply();

        if (0 < activity.Attachments?.Count)
        {
            if (activity.Attachments.FirstOrDefault().ContentType.Equals("image/jpg") ||
                activity.Attachments.FirstOrDefault().ContentType.Equals("image/jpeg") ||
                activity.Attachments.FirstOrDefault().ContentType.Equals("image/png") ||
                activity.Attachments.FirstOrDefault().ContentType.Equals("image/tiff"))
            {
                picImage = activity.Attachments.FirstOrDefault().Name;

                HttpClient httpClient= new HttpClient();
                picImageFile = await httpClient.GetByteArrayAsync(activity.Attachments.FirstOrDefault().ContentUrl);

                await context.PostAsync("Want to send another?");

                context.Wait(SendAnotherImage_ActivityReceivedAsync);
            }
        }
    }

更新:将WebClient更改为HttpClient.GetByteArrayAsync,问题仍然存在。
执行PostAsync后立即在Bot仿真器中显示该异常

UPDATE: Changed the WebClient to HttpClient.GetByteArrayAsync and the problem remains. The exception is shown in the Bot Emulator right after the PostAsync is executed

推荐答案

问题是 picImageFile 是对话框中的变量,由于对话框是序列化的,因此将其保存在状态中。两种选择

The problem is that picImageFile is a variable inside of your dialog, and so it's being saved in the state because the dialog is serialized. Two options


  1. 下载图像并以该方法处理它,而不将其保存在内存中

  2. 将字节数组保存在外部存储中。

这篇关于WebClient.DownloadData在Bot Framework中引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆