c# - Microsoft.AspNetCore.Routing.RouteValueDictionary 的 System.IndexOutOfRangeException
问题描述
我们在 Azure 上生产了一个 .NET Core 2.1 应用程序。它很少出现无法恢复的 500 错误,需要重新启动站点。我们注意到,在这些时间,我们的 Azure 应用程序洞察日志中出现了数百次以下异常/堆栈跟踪:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Microsoft.AspNetCore.Routing.RouteValueDictionary.ListStorage.Clear()
at Microsoft.AspNetCore.Routing.RouteValueDictionary.Clear()
at Microsoft.AspNetCore.Routing.RouteData.RouteDataSnapshot.Restore()
at Microsoft.AspNetCore.Routing.RouteCollection.<RouteAsync>d__9.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 Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.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 Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.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 Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__4.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 Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.<Invoke>d__3.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 Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.<Invoke>d__11.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 Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.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 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessRequestsAsync>d__2.MoveNext()
它令人困惑和令人沮丧,因为乍一看,所涉及的代码似乎都不是我们的,但也许是由于我们的路由中的某种错误配置?
作为参考,我们的 UseMvc 调用:
app.UseMvc(routes =>
{
var section = Configuration.GetSection("AppSettings:HostNames");
var hostnames = section.Get<string[]>();
// Prepare special routes
routes.MapRoute("takeSurveyApi", "TakeSurvey/{action}/{id?}", new { controller = "TakeSurvey", action = "Index" });
routes.MapRoute("takeSurvey", "TakeSurvey/{id?}", new { controller = "TakeSurvey", action = "Index" });
routes.MapRoute("stripeWebhook", "Billing/WebHook", new { controller = "Billing", action = "WebHook" });
routes.MapSubdomainRoute(
hostnames,
"MHP",
"{tenant}",
"MHP/{action}",
new { controller = "MHP", action = "GetTenantDetails" });
routes.MapSubdomainRoute(
hostnames,
"Localisation",
"{tenant}",
"Localisation/{action}",
new { controller = "Localisation", action = "Get" });
routes.MapSubdomainRoute(
hostnames,
"TenantInSubdomain",
"{tenant}",
"{*url}",
new { controller = "Home", action = "Index" });
routes.MapRoute(
hostnames,
"DefaultRoute",
"{controller}/{action}/{id?}",
new { controller = "Home", action = "Index" });
routes.MapRoute(
hostnames, "reactRouter", "{*url}", new {controller = "Home", action = "Index"});
});
有没有人遇到过类似的情况?
解决方案
推荐阅读
- javascript - 使用reduce函数汇总/计数数组
- perl - 将结果数据附加到 Parallel::ForkManager Perl 中的标量变量
- python - Pygame 程序在处理元组时崩溃
- php - 为什么 PHP cURL 请求可以在 localhost 上工作,但不能在服务器上工作(禁止 403)?
- jhipster - 在创建项目时全局保留一些 JHipster 设置以节省时间
- uniqueidentifier - ISBN/ISSN + Epubcfi 是否足以从外部链接到 Epub 段落?
- css - 在使用图像作为输入文件的输入类型文件中显示图像文件名
- java - Java中类之间的事件处理
- javascript - 有没有办法在 GTM 的循环中使用查找列表?
- vue.js - 设置属性并从 Vue 组件中检索 HTML 作为字符串