【发布时间】:2016-01-11 02:28:03
【问题描述】:
当我点击此 API 时,会抛出一个 TaskCanceledException 并带有无用的堆栈跟踪。我正在使用这个库:https://npoi.codeplex.com/
public class TestController : ApiController
{
[HttpGet]
public HttpResponseMessage Test()
{
var templateWorkbook = new XSSFWorkbook();
var sheet = templateWorkbook.CreateSheet("TestSheet");
IRow dataRow = sheet.CreateRow(4);
var cell = dataRow.CreateCell(0);
cell.SetCellValue(77);
Stream memoryStream = new MemoryStream();
templateWorkbook.Write(memoryStream);
var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(memoryStream)
};
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "test.xlsx" };
return httpResponseMessage;
}
}
我做错了什么?这是我的堆栈跟踪:
[TaskCanceledException:任务已取消。]
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+165
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+58
System.Web.Http.Owin.d__20.MoveNext() +666
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+137
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+58
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(任务任务)+25 System.Web.Http.Owin.d__0.MoveNext() +1814
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+137
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+58
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +187 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+58
Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +561
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+137
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+58
Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +561
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+137
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务) +58 Microsoft.Owin.Cors.d__0.MoveNext() +856
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+137
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+58
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +187 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+58
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__2.MoveNext() +185 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +69
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +64
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +380 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
【问题讨论】:
-
您能否在您的问题中确定哪一行引发了异常?
标签: excel asp.net-web-api async-await task npoi