473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.DataKeys[grdWorkout.SelectedIndex] is causing an
ArgumentOutOfRangeException, even though I had tested for SelectedIndex
== -1.

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

Thanks.
>>>>ERROR <<<<<
System.Web.HttpUnhandledException: Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(In t32 index)
at ASP.Workouts.btnSubstitute_Click(Object sender, ImageClickEventArgs e)
in d:\Inetpub\medicorpmap\Controls\Workouts.ascx:line 155
at System.Web.UI.WebControls.ImageButton.OnClick(Imag eClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBac kEvent(String
eventArgument)
at
System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.trainer_workouts_aspx.ProcessRequest(HttpConte xt context) in
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET
Files\root\f2d4905b\94fa3b3c\App_Web_amhr_qtk.2.cs :line 0
at
System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)
>>>>CODE <<<<<
if (ddlWorkouts.Items.Count == 0)
{
ErrorMessage1.SetError("You must first create one or more workouts before
you can exchange workout items.");
}
else if (grdWorkout.SelectedIndex == -1)
{
ErrorMessage1.SetError("You must first select an activity in the workout
before you can exchange it.");
}
else
{
EncryptedQueryString queries = new EncryptedQueryString();
queries["UserID"] = UserID.ToString();
object obj = TrainerID;
if (obj != null)
queries["TrainerID"] = obj.ToString();
queries["WorkoutID"] = ddlWorkouts.SelectedValue;
queries["WorkoutDetailID"] =
grdWorkout.DataKeys[grdWorkout.SelectedIndex].Value.ToString(); // <=====
LINE 155
Response.Redirect(String.Format("{0}?data={1}", SubstituteItemUrl,
queries), true);
}

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Jun 27 '08 #1
2 1317
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.DataKeys.Length 0)
queries["WorkoutDetailID"] =
grdWorkout.DataKeys[grdWorkout.SelectedIndex].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" <jw***@softcircuits.comwrote in message
news:#Q**************@TK2MSFTNGP04.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.DataKeys[grdWorkout.SelectedIndex] is causing an
ArgumentOutOfRangeException, even though I had tested for SelectedIndex
== -1.

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

Thanks.
>>>>>ERROR <<<<<

System.Web.HttpUnhandledException: Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(In t32 index)
at ASP.Workouts.btnSubstitute_Click(Object sender, ImageClickEventArgs
e) in d:\Inetpub\medicorpmap\Controls\Workouts.ascx:line 155
at System.Web.UI.WebControls.ImageButton.OnClick(Imag eClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBac kEvent(String
eventArgument)
at
System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.trainer_workouts_aspx.ProcessRequest(HttpConte xt context) in
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET
Files\root\f2d4905b\94fa3b3c\App_Web_amhr_qtk.2.cs :line 0
at
System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)
>>>>>CODE <<<<<

if (ddlWorkouts.Items.Count == 0)
{
ErrorMessage1.SetError("You must first create one or more workouts
before you can exchange workout items.");
}
else if (grdWorkout.SelectedIndex == -1)
{
ErrorMessage1.SetError("You must first select an activity in the workout
before you can exchange it.");
}
else
{
EncryptedQueryString queries = new EncryptedQueryString();
queries["UserID"] = UserID.ToString();
object obj = TrainerID;
if (obj != null)
queries["TrainerID"] = obj.ToString();
queries["WorkoutID"] = ddlWorkouts.SelectedValue;
queries["WorkoutDetailID"] =
grdWorkout.DataKeys[grdWorkout.SelectedIndex].Value.ToString(); // <=====
LINE 155
Response.Redirect(String.Format("{0}?data={1}", SubstituteItemUrl,
queries), true);
}

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Jun 27 '08 #2
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
http://www.softcircuits.com
"Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote in
message news:0D**********************************@microsof t.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.DataKeys.Length 0)
queries["WorkoutDetailID"] =
grdWorkout.DataKeys[grdWorkout.SelectedIndex].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" <jw***@softcircuits.comwrote in message
news:#Q**************@TK2MSFTNGP04.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.DataKeys[grdWorkout.SelectedIndex] is causing an
ArgumentOutOfRangeException, even though I had tested for SelectedIndex
== -1.

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

Thanks.
>>>>>>ERROR <<<<<

System.Web.HttpUnhandledException: Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(In t32 index)
at ASP.Workouts.btnSubstitute_Click(Object sender, ImageClickEventArgs
e) in d:\Inetpub\medicorpmap\Controls\Workouts.ascx:line 155
at System.Web.UI.WebControls.ImageButton.OnClick(Imag eClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBac kEvent(String
eventArgument)
at
System.Web.UI.WebControls.ImageButton.System.Web. UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.trainer_workouts_aspx.ProcessRequest(HttpConte xt context) in
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Tem porary ASP.NET
Files\root\f2d4905b\94fa3b3c\App_Web_amhr_qtk.2.c s:line 0
at
System.Web.HttpApplication.CallHandlerExecutionSt ep.System.Web.HttpApplication.IExecutionStep.Execu te()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)
>>>>>>CODE <<<<<

if (ddlWorkouts.Items.Count == 0)
{
ErrorMessage1.SetError("You must first create one or more workouts
before you can exchange workout items.");
}
else if (grdWorkout.SelectedIndex == -1)
{
ErrorMessage1.SetError("You must first select an activity in the
workout before you can exchange it.");
}
else
{
EncryptedQueryString queries = new EncryptedQueryString();
queries["UserID"] = UserID.ToString();
object obj = TrainerID;
if (obj != null)
queries["TrainerID"] = obj.ToString();
queries["WorkoutID"] = ddlWorkouts.SelectedValue;
queries["WorkoutDetailID"] =
grdWorkout.DataKeys[grdWorkout.SelectedIndex].Value.ToString(); // <=====
LINE 155
Response.Redirect(String.Format("{0}?data={1}", SubstituteItemUrl,
queries), true);
}

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Eric Boutin | last post by:
Hi ! I have a strange problem with a std::ostringstream.. code : #include <sstream> /*...*/ std::ostringstream ss(); ss << "\"\"" << libpath << "\"\" \"\"" << argfilename << "\"\"...
3
by: Jason | last post by:
I have two applications that I wrote that use asp and javascript source files. Recently both of these applications starting acting strange on my test box. Image icons will randomly stop showing...
3
by: Alfonso Morra | last post by:
I have some code that I am porting over from C. It is full of static functions and global variables. I have got around this by wrapping most of the code in a singleton object. However, I am...
12
by: ishtar2020 | last post by:
Hi everybody I've been writing my very first application in Python and everything is running smoothly, except for a strange problem that pops up every once in a while. I'm sure is the kind of...
1
by: Larax | last post by:
Alright, so here's the problem. I define a global variable in my script and then add methods/properties to it. Everything works great, no error in Javascript Console. But when I refresh site,...
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
0
by: AndreasJ.Mueller | last post by:
Hi Since we have moved our application (.NET 1.1) to a new server a few weeks ago we have seen in the event-logs multiple errors (which in itself is not my current problem, so I no...
28
by: charlie | last post by:
Hi, I found an article on informit.com that talks about C++ casts http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=285&rl=1 The strange thing is the author says the following...
11
by: VijaKhara | last post by:
Hi all, I just write a very simple codes in C and vthere is a very strange bug which I cannot figure out why. The first loop is for v, and the second for k. There is no relationship between v...
5
by: ioni | last post by:
Good day, fellows! I have a strange problem – at my site there is a flash strip, that loads data dynamically. It works fine (grabs data from the remote server and presents it), however in IE7...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.