Asp.net 页面加载的第一行出现奇怪且罕见的ArgumentOutOfRangeException

Asp.net 页面加载的第一行出现奇怪且罕见的ArgumentOutOfRangeException,asp.net,.net,exception,Asp.net,.net,Exception,我有一个用户控件,它在大多数情况下可以处理数千个请求,但通常每天一到两次,在aspx.vb文件的代码后面有一个ArgumentOutOfRangeException,它指向Page_Load方法的第一行。我从未能够自己复制它,但我记录了错误的详细信息/堆栈跟踪。问题是,我确信错误实际上没有发生在Page_加载块中,尽管堆栈跟踪表明不是这样。事实上,我在那里有什么代码并不重要,为了证明这一点,我在页面加载中放入了一些伪代码,发布并等待下一次出现,如下所示 Protected Sub Pag

我有一个用户控件,它在大多数情况下可以处理数千个请求,但通常每天一到两次,在aspx.vb文件的代码后面有一个ArgumentOutOfRangeException,它指向Page_Load方法的第一行。我从未能够自己复制它,但我记录了错误的详细信息/堆栈跟踪。问题是,我确信错误实际上没有发生在Page_加载块中,尽管堆栈跟踪表明不是这样。事实上,我在那里有什么代码并不重要,为了证明这一点,我在页面加载中放入了一些伪代码,发布并等待下一次出现,如下所示

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim abc As Integer = 123
        abc = abc + 1
        ...
    End Sub
果然,当错误最终再次发生时,它仍然指向页面加载的第一行(第16行:Dim abc As Integer=123)。显然,这不是生成ArgumentOutOfRangeException的语句类型

Type: System.ArgumentOutOfRangeException
Message: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source: mscorlib
TargetSite: Void ThrowArgumentOutOfRangeException()
StackTrace:    at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at aut.ProductWithColorChoice.Page_Load(Object sender, EventArgs e) in F:\Visual Studio Projects\1003\templates\usercontrols\ProductWithColorChoice.ascx.vb:line 16
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
在.ascx页面上使用的唯一一个内联代码实际上是在javascript块中找到的,用于获取控件的ClientId,以便在页面完全加载之前禁用控件

<%@ Control Language="vb" AutoEventWireup="false" Inherits="aut.ProductWithColorChoice" %>
<script language="javascript" type="text/javascript">
(function () {
    Sys.Application.add_load(setupButtonDisablers);
    function setupButtonDisablers() {
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(onPageLoad);
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(onSubmit);
        Sys.Application.remove_load(setupButtonDisablers);
    }
    function onPageLoad() {
        findAndEnable('<%= AddToCartImageButton.ClientID %>');
    }
    function onSubmit() {
        findAndDisable('<%= YearDropDownList.ClientID %>');
        findAndDisable('<%= MakeDropDownList.ClientID %>');
        findAndDisable('<%= ModelDropDownList.ClientID %>');
        findAndDisable('<%= ColorDropDownList.ClientID %>');
        findAndDisable('<%= AddToCartImageButton.ClientID %>');
    }
    function findAndDisable(id) { findAndSetDisabledProperty(id, true); }
    function findAndEnable(id) { findAndSetDisabledProperty(id, false); }
    function findAndSetDisabledProperty(id, value) {
        var control = $get(id);
        if (control) control.disabled = value;
        else alert('could not find ' + id);
    }
})();
</script>

您是否在页面或可能的事件中的某个位置设置下拉列表的选定值?实际上,您不认为它与DropDownList相关,因为它有不同的错误消息:“System.ArgumentOutOfRangeException:“DropDownList”有一个SelectedValue,该值无效,因为它不在项目列表中。”我得到的错误是“指数超出范围。必须为非负数且小于集合的大小。“
    If My.Settings.PaintSizes.Contains(SizeOption) Then
        sizeIndex = My.Settings.PaintSizes.IndexOf(SizeOption)            
        Price = Decimal.Parse(My.Settings.RegularPaintPrices(sizeIndex))
        Weight = Double.Parse(My.Settings.PaintWeights(sizeIndex))
    Else
        Throw New ApplicationException(Me.ID & ": sizeoption must match exactly one of the values in PaintSizes located in the web.config file")
    End If