- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已升级到 ASP.NET Web API 5.2.2,现在在我的生产 Elmah 日志中看到以下异常。
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
最佳答案
这看起来与这个问题非常相似:ASP.NET Web API OperationCanceledException when browser cancels the request
接受的答案( https://stackoverflow.com/a/22621596/124165 )是此处已针对此问题提交了错误:http://aspnetwebstack.codeplex.com/workitem/1797
以下是上述源代码中用于解决此问题的代码片段:
In the meantime, you could try something like the code below. It adds a top-level message handler that removes the content when the cancellation token fires. If the response has no content, the bug shouldn't be triggered. There's still a small possibility it could happen, because the client could disconnect right after the message handler checks the cancellation token but before the higher-level Web API code does the same check. But I think it will help in most cases.
config.MessageHandlers.Add(new CancelledTaskBugWorkaroundMessageHandler());
class CancelledTaskBugWorkaroundMessageHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
// Try to suppress response content when the cancellation token has fired; ASP.NET will log to the Application event log if there's content in this case.
if (cancellationToken.IsCancellationRequested)
{
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
}
return response;
}
}
关于asp.net - Web Api TaskCanceledException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27428769/
我正在努力使我们的一个应用程序异步,现在当我调用 SendAsync 时我的 HttpClient 超时(我得到一个 TaskCanceledException)。这是超时的代码:
所以首先,我有多个窗口,在打开另一个窗口时会隐藏这些窗口,所以我必须使用 Application.Current.Shutdown(); 按右上角的“x”完全关闭应用程序。 我想在我的 Home.xa
每当我按照 When at last you await 中的指南同步返回另一个任务而不是等待它时,我似乎得到一个 TaskCanceledException . TaskCanceledExcept
我有以下测试代码: void Button_Click(object sender, RoutedEventArgs e) { var source = new CancellationTok
我的应用程序使用 Azure 存储 blob 将文件从远程存储下载到本地计算机。 工作原理: 计算机获取带有 Azure 存储 blob 的 URL(签名 URL)的队列消息。 应用程序发送 GET
我有一个发送电子邮件的功能,如下所示: public async Task SendEmail(string from, string to, string subject, string body,
我们目前看到很多 TaskCanceledException 被 MS.Internal.ShutDownListener.HandleShutDown 抛出。这开始于 5 月中旬,可能与 .Net
我正在深入研究 async-await 机制并观察到抛出一个我还无法解释的 TaskCanceledException。 在下面的示例中(独立的)我有声明 await Task.Run(() => n
我是 C# 的新手,我发现异常有点令人困惑...我有一个包含以下代码的网络应用程序: try { //do something } catch (TimeoutException t) {
我有一个服务总线触发器 Azure 函数,每次主题收到消息时都会触发该函数。消息定期到达,例如每 30 分钟一次。批处理之间没有事件。 该函数没有做任何特殊的事情,它通过 HttpClient 异步发
我一直在试图弄清楚为什么我会因为一些最近开始行为不端的异步代码而收到 TaskCanceledException。我已经将我的问题简化为一个让我挠头的小代码片段: static void Main(s
我已升级到 ASP.NET Web API 5.2.2,现在在我的生产 Elmah 日志中看到以下异常。 System.Threading.Tasks.TaskCanceledException: A
我有一个方法可以创建一些任务,然后用 WaitAll 等待它们在返回之前。问题是,如果这些任务被取消,那么 WaitAll 会抛出 AggregateException包含大量 TaskCancele
我对此一筹莫展。我尝试在 Microsoft 合规性中心启动合规性搜索,但遇到了此错误。 Creating SearchA task was canceled. + CategoryInfo
我尝试在 asp.net identity 2.0 应用程序中发送验证电子邮件地址电子邮件,但收到 TaskCanceledException 错误。 我尝试了这个线程中的内容:Asp.Net Ide
我有一个工作代码从我的 CommonRestClient 返回一些东西(它是 HttpClient 的简单包装器): public async Task Index() { var uri =
在大约 24 小时的时间内,我们在一台特定服务器上收到了数千个页面加载错误。错误采用以下形式: Event code: 3005 Event message: An unhandled excepti
我有一个应用程序 (UWP - Win10) 和一个 Windows 服务。 该服务在后台运行,它们都是用 C# 开发的。 “callAsync”是服务上的方法。我正在使用 await 在客户端调用它
我正在使用任务并行库来运行一个任务,该任务在取消时会抛出 OperationCanceledException,然后使用 AggregateException 捕获该异常,如下所示。 Aggregat
我不明白调用 SendMailAsync 的这两种实现之间的区别。大多数情况下,对于第一个,我会收到 TaskCanceledException,但对于第二个,一切都按预期进行。 我认为这两种消费方法
我是一名优秀的程序员,十分优秀!