1

我正在选择一个旧的 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 项目。

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

4

3 回答 3

1

好的,通过大量的试验和错误,我想我已经弄清楚了。

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

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

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

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

出现上述异常。如果包含的文件仅包含纯文本/html,则它可以正常工作,仅当存在代码块时。

This worked prior to upgrading to Visual Studio 2012, so it seems to be a vs 2012 parser bug...

于 2012-09-28T17:03:44.153 回答
1

So, this seems to be a bug in Microsoft Page Inspector. You can tell VS2012 to use Page Inspector instead of Chrome/IE/Firefox when debugging web sites. However, I do not understand why the Page Inspector is involved when I have chosen not to use it, but it is there. To me, it caused both the call stack above and it causes HTML documents to be clipped half way through.

The best solution I have found is to disable the Page Inspector by removing its assembly, in web.config:

<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>
于 2012-11-29T09:34:59.107 回答
0

我最好的猜测——这只是一个猜测——是基于出现在你的堆栈跟踪中的模块。

我猜你的构建中发生了一些复杂的事情,或者你的页面上有格式错误的标签或某种编译器指令。

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

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

于 2012-09-27T21:17:46.770 回答