问题
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);
}
}
}
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
回答1:
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
- Download the image and process it in that method, without saving it in memory
- Save the byte array in an external storage.
来源:https://stackoverflow.com/questions/46645806/webclient-downloaddata-throws-an-exception-in-bot-framework