首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试/捕捉不捕获HttpListenerException

尝试/捕捉不捕获HttpListenerException
EN

Stack Overflow用户
提问于 2019-04-03 12:58:24
回答 2查看 399关注 0票数 0

我使用Grapevine创建了一个简单的http端点(它只是HttpListener的一个接口)。有时,连接在我的SendResponse之前下降,这导致了一个HttpListenerException,但我不明白为什么try/catch不处理异常,整个服务器崩溃。

错误:

代码语言:javascript
复制
Application: Movimiento de Placas.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Net.HttpListenerException
Stack:
   at System.Net.HttpResponseStream.Write(Byte[], Int32, Int32)
   at Grapevine.Interfaces.Server.HttpResponse.SendResponse(Byte[])
   at Grapevine.Server.HttpResponseExtensions.SendResponse(Grapevine.Interfaces.Server.IHttpResponse, System.String)
   at Grapevine.Server.Router.Route(System.Object)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

代码:

代码语言:javascript
复制
[RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "/patente")]
        public IHttpContext ModificarPantalla(IHttpContext context)
        {
            var dict = HttpUtility.ParseQueryString(context.Request.Payload);
            var json = new JavaScriptSerializer().Serialize(
                dict.Keys.Cast<string>()
                    .ToDictionary(k => k, k => dict[k]));
            var contenido = JsonConvert.DeserializeObject<Patente>(json);
            Server.FormRef.CargarPatente(contenido.Plate, contenido.idCamera);
            UltimaFoto.Fecha = DateTime.Now;
            Task.Run(() => Sqlite.InsertarPatente(contenido));
            try
            {
                context.Response.SendResponse(HttpStatusCode.Ok); //exception occurs here
            }
            catch (Exception ex)
            {

            }

            return context;
        }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-17 23:11:37

这是一个众所周知的问题。有一个公关,已经徘徊了一段时间,现在解决了这个问题,我正在合并它,同时更新将增加对.NET标准的支持。这应该可以在本周末买到。

更新:截至2019年8月9日,葡萄4.1.2可在Nuget.org上获得

票数 1
EN

Stack Overflow用户

发布于 2019-04-03 13:14:07

如果SendResponse是异步的,而且您没有等待它,这种情况可能会发生。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55495797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档