问题描述
AggregateException是扔在等待API后,完成我怎么能解决这个问题?
我的API调用是这样的类似
使用(VAR的HttpClient =新的HttpClient())
{
httpClient.BaseAddress =新的URI(workflowUrl);
VAR任务= httpClient.PostAsJsonAsync(API / apiname /执行/,executeModel)
.ContinueWith(X => x.Result.Content.ReadAsAsync<布尔>()的结果。); 任务延续= task.ContinueWith(X =>
{
布尔响应= x.Result;
});
continuation.Wait();}
我得到异常如下而waitng完成POST。
System.AggregateException被抓
消息=发生一个或多个错误。
来源= mscorlib程序
堆栈跟踪:
在System.Threading.Tasks.Task.ThrowIfExceptional(布尔includeTaskCanceledExceptions)
在System.Threading.Tasks.Task.Wait(的Int32 millisecondsTimeout,的CancellationToken的CancellationToken)
在System.Threading.Tasks.Task.Wait()
在
的InnerException:System.AggregateException
消息=发生一个或多个错误。
来源= mscorlib程序
堆栈跟踪:
在System.Threading.Tasks.Task.ThrowIfExceptional(布尔includeTaskCanceledExceptions)
在System.Threading.Tasks.Task`1.get_Result()
在
在System.Threading.Tasks.Task`1<方式>&c__DisplayClass17 LT; ContinueWith> b__16(obj对象)
在System.Threading.Tasks.Task.InnerInvoke()
在System.Threading.Tasks.Task.Execute()
的InnerException:System.AggregateException
消息=发生一个或多个错误。
来源= mscorlib程序
堆栈跟踪:
在System.Threading.Tasks.Task.ThrowIfExceptional(布尔includeTaskCanceledExceptions)
在System.Threading.Tasks.Task`1.get_Result()
在WebUI.ListController< ListRepeater_ItemCommand> b__f(Task`1 X)在PostAsJsonAsync:741线
在System.Threading.Tasks.Task`1<方式>&c__DisplayClass1a`1 LT; ContinueWith> b__19()
在System.Threading.Tasks.Task`1.InvokeFuture(对象futureAsObj)
在System.Threading.Tasks.Task.InnerInvoke()
在System.Threading.Tasks.Task.Execute()
的InnerException:System.Threading.Tasks.TaskCanceledException
消息=任务被取消。
的InnerException:
您发布一大块的数据?我曾有过一个类似的问题。我认为,根本的问题是偶尔超时由于带宽的问题。我试图让任务和手动等待它,然后检查 .IsFaulted
和 .IsCancelled
但。结果
抛出 AggregateException
/ TaskCancelledException
。
也许你应该尝试增加HttpClient.Timeout财产是100秒默认?
AggregateException is throwing while waiting for API post to complete how i could fix this?
My API call is similar like this
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(workflowUrl);
var task = httpClient.PostAsJsonAsync("api/apiname/execute/", executeModel)
.ContinueWith(x => x.Result.Content.ReadAsAsync<bool>().Result);
Task continuation = task.ContinueWith(x =>
{
bool response = x.Result;
});
continuation.Wait();
}
I am getting Exception given below while waitng for POST to complete.
System.AggregateException was caught
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at
InnerException: System.AggregateException
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.get_Result()
at
at System.Threading.Tasks.Task`1.<>c__DisplayClass17.<ContinueWith>b__16(Object obj)
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException: System.AggregateException
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.get_Result()
at WebUI.ListController.<ListRepeater_ItemCommand>b__f(Task`1 x) in PostAsJsonAsync:line 741
at System.Threading.Tasks.Task`1.<>c__DisplayClass1a`1.<ContinueWith>b__19()
at System.Threading.Tasks.Task`1.InvokeFuture(Object futureAsObj)
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
InnerException: System.Threading.Tasks.TaskCanceledException
Message=A task was canceled.
InnerException:
Are you posting a big piece of data ? Once I had a similar issue. I believe the underlying problem is occasional timeout due to bandwidth issues. I tried getting the task and manually waiting on it then checking .IsFaulted
and .IsCancelled
but the .Result
throws AggregateException
/ TaskCancelledException
.
Maybe you should try to increase HttpClient.Timeout property which is 100 sec by default ?
这篇关于在等待PostAsJsonAsync AggregateException抛出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!