Strange Errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Wood

    #1

    Strange Errors

    I'm having my site email errors to me until I get things as stable as
    possible. Occasionally, I get an error that I just cannot see how it could
    ever happen. I enabled debugging on the live site so that I could get
    line-number information. But I'm still at a loss.

    I've posted an error below, and the code below that. Somehow,
    grdWorkout.Data Keys[grdWorkout.Sele ctedIndex] is causing an
    ArgumentOutOfRa ngeException, even though I had tested for SelectedIndex
    == -1.

    Does anyone have any clues as to how this could happen?

    Thanks.
    >>>>ERROR <<<<<
    System.Web.Http UnhandledExcept ion: Exception of type
    'System.Web.Htt pUnhandledExcep tion' was thrown. --->
    System.Argument OutOfRangeExcep tion: Index was out of range. Must be
    non-negative and less than the size of the collection.
    Parameter name: index
    at System.Collecti ons.ArrayList.g et_Item(Int32 index)
    at System.Web.UI.W ebControls.Data KeyArray.get_It em(Int32 index)
    at ASP.Workouts.bt nSubstitute_Cli ck(Object sender, ImageClickEvent Args e)
    in d:\Inetpub\medi corpmap\Control s\Workouts.ascx :line 155
    at System.Web.UI.W ebControls.Imag eButton.OnClick (ImageClickEven tArgs e)
    at System.Web.UI.W ebControls.Imag eButton.RaisePo stBackEvent(Str ing
    eventArgument)
    at
    System.Web.UI.W ebControls.Imag eButton.System. Web.UI.IPostBac kEventHandler.R aisePostBackEve nt(String
    eventArgument)
    at System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
    sourceControl, String eventArgument)
    at System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
    at System.Web.UI.P age.ProcessRequ estMain(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
    --- End of inner exception stack trace ---
    at System.Web.UI.P age.HandleError (Exception e)
    at System.Web.UI.P age.ProcessRequ estMain(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
    at System.Web.UI.P age.ProcessRequ est(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
    at System.Web.UI.P age.ProcessRequ est()
    at System.Web.UI.P age.ProcessRequ estWithNoAssert (HttpContext context)
    at System.Web.UI.P age.ProcessRequ est(HttpContext context)
    at ASP.trainer_wor kouts_aspx.Proc essRequest(Http Context context) in
    c:\WINDOWS\Micr osoft.NET\Frame work\v2.0.50727 \Temporary ASP.NET
    Files\root\f2d4 905b\94fa3b3c\A pp_Web_amhr_qtk .2.cs:line 0
    at
    System.Web.Http Application.Cal lHandlerExecuti onStep.System.W eb.HttpApplicat ion.IExecutionS tep.Execute()
    at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean&
    completedSynchr onously)
    >>>>CODE <<<<<
    if (ddlWorkouts.It ems.Count == 0)
    {
    ErrorMessage1.S etError("You must first create one or more workouts before
    you can exchange workout items.");
    }
    else if (grdWorkout.Sel ectedIndex == -1)
    {
    ErrorMessage1.S etError("You must first select an activity in the workout
    before you can exchange it.");
    }
    else
    {
    EncryptedQueryS tring queries = new EncryptedQueryS tring();
    queries["UserID"] = UserID.ToString ();
    object obj = TrainerID;
    if (obj != null)
    queries["TrainerID"] = obj.ToString();
    queries["WorkoutID"] = ddlWorkouts.Sel ectedValue;
    queries["WorkoutDetailI D"] =
    grdWorkout.Data Keys[grdWorkout.Sele ctedIndex].Value.ToString (); // <=====
    LINE 155
    Response.Redire ct(String.Forma t("{0}?data={1} ", SubstituteItemU rl,
    queries), true);
    }

    --
    Jonathan Wood
    SoftCircuits Programming


  • Alvin Bruney [ASP.NET MVP]

    #2
    Re: Strange Errors

    You tested for -1 on selectedindex, you have not tested for the validity of
    the datakeys collection which is where the error is coming from. What you
    need is this:

    if(grdWorkout.D ataKeys.Length 0)
    queries["WorkoutDetailI D"] =
    grdWorkout.Data Keys[grdWorkout.Sele ctedIndex].Value.ToString ();

    The datakeys collection holds keys relating to the records in the bound
    control. However, the framework does not explicitly guarantee that these
    keys will available when you need them. There is only a reasonable
    expectation that the keys will be available. You must test the collection
    before you use it - test and load pattern.

    This isn't a common occurrence, you will likely hit this every once in a
    while and typically while the site is under heavy load. I suspect that this
    is related to a locked collection in the framework at the moment of access
    but that's just a wild guess based on similar occurrences with collections.

    --

    Regards,
    Alvin Bruney [MVP ASP.NET]

    [Shameless Author plug]
    The O.W.C. Black Book, 2nd Edition
    Exclusively on www.lulu.com/owc $19.99
    -------------------------------------------------------


    "Jonathan Wood" <jwood@softcirc uits.comwrote in message
    news:#QuPX$lzIH A.2384@TK2MSFTN GP04.phx.gbl...
    I'm having my site email errors to me until I get things as stable as
    possible. Occasionally, I get an error that I just cannot see how it could
    ever happen. I enabled debugging on the live site so that I could get
    line-number information. But I'm still at a loss.
    >
    I've posted an error below, and the code below that. Somehow,
    grdWorkout.Data Keys[grdWorkout.Sele ctedIndex] is causing an
    ArgumentOutOfRa ngeException, even though I had tested for SelectedIndex
    == -1.
    >
    Does anyone have any clues as to how this could happen?
    >
    Thanks.
    >
    >>>>>ERROR <<<<<
    >
    System.Web.Http UnhandledExcept ion: Exception of type
    'System.Web.Htt pUnhandledExcep tion' was thrown. --->
    System.Argument OutOfRangeExcep tion: Index was out of range. Must be
    non-negative and less than the size of the collection.
    Parameter name: index
    at System.Collecti ons.ArrayList.g et_Item(Int32 index)
    at System.Web.UI.W ebControls.Data KeyArray.get_It em(Int32 index)
    at ASP.Workouts.bt nSubstitute_Cli ck(Object sender, ImageClickEvent Args
    e) in d:\Inetpub\medi corpmap\Control s\Workouts.ascx :line 155
    at System.Web.UI.W ebControls.Imag eButton.OnClick (ImageClickEven tArgs e)
    at System.Web.UI.W ebControls.Imag eButton.RaisePo stBackEvent(Str ing
    eventArgument)
    at
    System.Web.UI.W ebControls.Imag eButton.System. Web.UI.IPostBac kEventHandler.R aisePostBackEve nt(String
    eventArgument)
    at System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
    sourceControl, String eventArgument)
    at System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
    at System.Web.UI.P age.ProcessRequ estMain(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
    --- End of inner exception stack trace ---
    at System.Web.UI.P age.HandleError (Exception e)
    at System.Web.UI.P age.ProcessRequ estMain(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
    at System.Web.UI.P age.ProcessRequ est(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)
    at System.Web.UI.P age.ProcessRequ est()
    at System.Web.UI.P age.ProcessRequ estWithNoAssert (HttpContext context)
    at System.Web.UI.P age.ProcessRequ est(HttpContext context)
    at ASP.trainer_wor kouts_aspx.Proc essRequest(Http Context context) in
    c:\WINDOWS\Micr osoft.NET\Frame work\v2.0.50727 \Temporary ASP.NET
    Files\root\f2d4 905b\94fa3b3c\A pp_Web_amhr_qtk .2.cs:line 0
    at
    System.Web.Http Application.Cal lHandlerExecuti onStep.System.W eb.HttpApplicat ion.IExecutionS tep.Execute()
    at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean&
    completedSynchr onously)
    >
    >>>>>CODE <<<<<
    >
    if (ddlWorkouts.It ems.Count == 0)
    {
    ErrorMessage1.S etError("You must first create one or more workouts
    before you can exchange workout items.");
    }
    else if (grdWorkout.Sel ectedIndex == -1)
    {
    ErrorMessage1.S etError("You must first select an activity in the workout
    before you can exchange it.");
    }
    else
    {
    EncryptedQueryS tring queries = new EncryptedQueryS tring();
    queries["UserID"] = UserID.ToString ();
    object obj = TrainerID;
    if (obj != null)
    queries["TrainerID"] = obj.ToString();
    queries["WorkoutID"] = ddlWorkouts.Sel ectedValue;
    queries["WorkoutDetailI D"] =
    grdWorkout.Data Keys[grdWorkout.Sele ctedIndex].Value.ToString (); // <=====
    LINE 155
    Response.Redire ct(String.Forma t("{0}?data={1} ", SubstituteItemU rl,
    queries), true);
    }
    >
    --
    Jonathan Wood
    SoftCircuits Programming

    >

    Comment

    • Jonathan Wood

      #3
      Re: Strange Errors

      Alvin,

      Perhaps that's it. But if so then I don't get how DataKeys could ever be
      empty. In my GridView, DataKeyNames is equal to one of the bound fields (the
      primary key). Since this normally works, I know it's spelled correctly, etc.

      Can you imagine any scenario where this would result in an empty DataKeys
      collection?

      And if this isn't odd enough, the user at the time is clear that he didn't
      get any error. I wish I could explain a couple of things I'm curretnly
      seeing.

      Thanks.

      --
      Jonathan Wood
      SoftCircuits Programming



      "Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote in
      message news:0D73DC61-8E7D-4E57-96BF-26AD4DCCA7F8@mi crosoft.com...
      You tested for -1 on selectedindex, you have not tested for the validity
      of the datakeys collection which is where the error is coming from. What
      you need is this:
      >
      if(grdWorkout.D ataKeys.Length 0)
      queries["WorkoutDetailI D"] =
      grdWorkout.Data Keys[grdWorkout.Sele ctedIndex].Value.ToString ();
      >
      The datakeys collection holds keys relating to the records in the bound
      control. However, the framework does not explicitly guarantee that these
      keys will available when you need them. There is only a reasonable
      expectation that the keys will be available. You must test the collection
      before you use it - test and load pattern.
      >
      This isn't a common occurrence, you will likely hit this every once in a
      while and typically while the site is under heavy load. I suspect that
      this is related to a locked collection in the framework at the moment of
      access but that's just a wild guess based on similar occurrences with
      collections.
      >
      --
      >
      Regards,
      Alvin Bruney [MVP ASP.NET]
      >
      [Shameless Author plug]
      The O.W.C. Black Book, 2nd Edition
      Exclusively on www.lulu.com/owc $19.99
      -------------------------------------------------------
      >
      >
      "Jonathan Wood" <jwood@softcirc uits.comwrote in message
      news:#QuPX$lzIH A.2384@TK2MSFTN GP04.phx.gbl...
      >I'm having my site email errors to me until I get things as stable as
      >possible. Occasionally, I get an error that I just cannot see how it
      >could ever happen. I enabled debugging on the live site so that I could
      >get line-number information. But I'm still at a loss.
      >>
      >I've posted an error below, and the code below that. Somehow,
      >grdWorkout.Dat aKeys[grdWorkout.Sele ctedIndex] is causing an
      >ArgumentOutOfR angeException, even though I had tested for SelectedIndex
      >== -1.
      >>
      >Does anyone have any clues as to how this could happen?
      >>
      >Thanks.
      >>
      >>>>>>ERROR <<<<<
      >>
      >System.Web.Htt pUnhandledExcep tion: Exception of type
      >'System.Web.Ht tpUnhandledExce ption' was thrown. --->
      >System.Argumen tOutOfRangeExce ption: Index was out of range. Must be
      >non-negative and less than the size of the collection.
      >Parameter name: index
      > at System.Collecti ons.ArrayList.g et_Item(Int32 index)
      > at System.Web.UI.W ebControls.Data KeyArray.get_It em(Int32 index)
      > at ASP.Workouts.bt nSubstitute_Cli ck(Object sender, ImageClickEvent Args
      >e) in d:\Inetpub\medi corpmap\Control s\Workouts.ascx :line 155
      > at System.Web.UI.W ebControls.Imag eButton.OnClick (ImageClickEven tArgs e)
      > at System.Web.UI.W ebControls.Imag eButton.RaisePo stBackEvent(Str ing
      >eventArgumen t)
      > at
      >System.Web.UI. WebControls.Ima geButton.System .Web.UI.IPostBa ckEventHandler. RaisePostBackEv ent(String
      >eventArgumen t)
      > at System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
      >sourceContro l, String eventArgument)
      > at System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
      > at System.Web.UI.P age.ProcessRequ estMain(Boolean
      >includeStagesB eforeAsyncPoint , Boolean includeStagesAf terAsyncPoint)
      > --- End of inner exception stack trace ---
      > at System.Web.UI.P age.HandleError (Exception e)
      > at System.Web.UI.P age.ProcessRequ estMain(Boolean
      >includeStagesB eforeAsyncPoint , Boolean includeStagesAf terAsyncPoint)
      > at System.Web.UI.P age.ProcessRequ est(Boolean
      >includeStagesB eforeAsyncPoint , Boolean includeStagesAf terAsyncPoint)
      > at System.Web.UI.P age.ProcessRequ est()
      > at System.Web.UI.P age.ProcessRequ estWithNoAssert (HttpContext context)
      > at System.Web.UI.P age.ProcessRequ est(HttpContext context)
      > at ASP.trainer_wor kouts_aspx.Proc essRequest(Http Context context) in
      >c:\WINDOWS\Mic rosoft.NET\Fram ework\v2.0.5072 7\Temporary ASP.NET
      >Files\root\f2d 4905b\94fa3b3c\ App_Web_amhr_qt k.2.cs:line 0
      > at
      >System.Web.Htt pApplication.Ca llHandlerExecut ionStep.System. Web.HttpApplica tion.IExecution Step.Execute()
      > at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean&
      >completedSynch ronously)
      >>
      >>>>>>CODE <<<<<
      >>
      > if (ddlWorkouts.It ems.Count == 0)
      > {
      > ErrorMessage1.S etError("You must first create one or more workouts
      >before you can exchange workout items.");
      > }
      > else if (grdWorkout.Sel ectedIndex == -1)
      > {
      > ErrorMessage1.S etError("You must first select an activity in the
      >workout before you can exchange it.");
      > }
      > else
      > {
      > EncryptedQueryS tring queries = new EncryptedQueryS tring();
      > queries["UserID"] = UserID.ToString ();
      > object obj = TrainerID;
      > if (obj != null)
      > queries["TrainerID"] = obj.ToString();
      > queries["WorkoutID"] = ddlWorkouts.Sel ectedValue;
      > queries["WorkoutDetailI D"] =
      >grdWorkout.Dat aKeys[grdWorkout.Sele ctedIndex].Value.ToString (); // <=====
      >LINE 155
      > Response.Redire ct(String.Forma t("{0}?data={1} ", SubstituteItemU rl,
      >queries), true);
      > }
      >>
      >--
      >Jonathan Wood
      >SoftCircuits Programming
      >http://www.softcircuits.com
      >>

      Comment

      Working...