Asp.net mvc 4 asp.net mvc 4应用程序启动时出现不明确的异常-索引和长度必须引用字符串中的位置。参数名称:长度

Asp.net mvc 4 asp.net mvc 4应用程序启动时出现不明确的异常-索引和长度必须引用字符串中的位置。参数名称:长度,asp.net-mvc-4,Asp.net Mvc 4,这是堆栈跟踪 [ArgumentOutOfRangeException: Index and length must refer to a location within the string. Parameter name: length] System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +10699039 System.Web.HttpApp

这是堆栈跟踪

[ArgumentOutOfRangeException: Index and length must refer to a location within the     string.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean  fAlwaysCopy) +10699039
System.Web.HttpApplication.HookupEventHandlersForApplicationAndModules(MethodInfo[] handlers) +312
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +107
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Index and length must refer to a location within the string.
Parameter name: length]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874568
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

除了到处抛出随机断点之外,还有什么方法可以找出这个异常的来源吗?谢谢

我遇到了同样的问题,并且能够解决它


事实证明,在Global.asax.cs中的某个时候,我胖手指碰到了什么东西。我最终将方法
Application\u Error
更改为
Application\u
(后面有一行新行,愚蠢的宽手指…)。这就是导致我出现错误的原因。将其重写为
应用程序\u错误
解决了问题。

您可以中断所有CLR异常。在VisualStudio中,单击“调试”菜单,然后选择“异常”并选中公共语言运行时异常旁边的复选框。我这样做了,但它仍然没有破坏任何特定的地方。我也检查了它们,开始得到一个奇怪的log4net未被发现的异常,但我发现这不重要。