ASP.NET WebForms“长度不能小于0或超过输入长度。”在应用程序启动

时间:2012-09-27 21:03:33

标签: asp.net webforms compiler-errors visual-studio-2012

我正在接受一个旧的ASP.NET WebForms项目,我在启动时得到了这个:

  

长度不能小于0或超过输入长度。参数名称:   长度

令人费解的是,我的应用程序代码在堆栈跟踪中无处可用。这是显示的内容:

[ArgumentOutOfRangeException: Length cannot be less than 0 or exceed input length.
Parameter name: length]
   System.Text.RegularExpressions.Regex.Run(Boolean quick, Int32 prevlen, String input, Int32 beginning, Int32 length, Int32 startat) +6697802
   System.Text.RegularExpressions.Regex.Match(String input, Int32 beginning, Int32 length) +48
   Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.LiteralWithCommentsHelper.FindComments(String source, Int32 sourceStart, Int32 sourceEnd) +89
   Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.LiteralWithCommentsHelper..ctor(String source, Int32 sourceStart, Int32 sourceEnd) +27
   Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingParseRecorder.PostProcessBlockList() +311
   Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingParseRecorder.BuildBlockList(ControlBuilder root) +100
   Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingParseRecorder.ParseComplete(ControlBuilder root) +101
   System.Web.UI.ParseRecorderList.ParseComplete(ControlBuilder root) +71
   System.Web.UI.TemplateParser.HandlePostParse() +184
   System.Web.UI.TemplateControlParser.HandlePostParse() +13
   System.Web.UI.PageParser.HandlePostParse() +12
   System.Web.UI.TemplateParser.Parse() +154
   System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType() +110
   System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) +59
   System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() +209
   System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +15
   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +9929933
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +299
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +103
   System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) +165
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +43
   System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31
   System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +64
   System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +191
   System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +145
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

我刚刚接受了这个项目,所以我不确定发生了什么变化,但我知道它在过去的某个时刻有效。 :)最近,我将项目文件从VS 2010升级到VS 2012,但是没有发出任何警告,因此这似乎是一件奇怪的事情。它是用VB.NET编写的.NET 4.0项目。

关于在哪里寻找或如何进一步诊断的任何想法?

3 个答案:

答案 0 :(得分:1)

通过大量的试验和错误,我想我已经弄明白了。

罪魁祸首是aspx页面中的服务器端包含:

<!-- #include file="include/header.inc" -->

当包含的文件包含代码块时,即

<% Response.Write("Im broken") %>

发生上述异常。如果包含的文件只包含纯文本/ html,它可以正常工作,只有在存在代码块时才能正常工作。

这在升级到Visual Studio 2012之前有效,因此它似乎是vs 2012解析器错误......

答案 1 :(得分:1)

因此,这似乎是Microsoft Page Inspector中的一个错误。在调试网站时,您可以告诉VS2012使用Page Inspector而不是Chrome / IE / Firefox。但是,当我选择不使用它时,我不明白为什么Page Inspector会参与其中,但它就在那里。对我来说,它导致了上面的调用堆栈,它导致HTML文档被中途修剪。

我找到的最佳解决方案是在web.config中删除其程序集来禁用Page Inspector:

<compilation defaultLanguage="c#" debug="true" targetFramework="4.0">
  <assemblies>
    <remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </assemblies>
</compilation>

答案 2 :(得分:0)

我最好的猜测 - 这只是猜测 - 基于堆栈跟踪中出现的模块。

我猜你的构建中有一些复杂的东西,或者你的页面上有某种格式错误的标记或编译器指令。

检查项目文件,看看是否有任何特殊的构建脚本,构建事件等。

您可以尝试将启动页面加载到设计器中,看看会发生什么。有任何警告或信息消息吗?任何错误的字形?红线?