We have a project that use in .NET 2.0 and it works. However, when we upgrade it to .NET 4.5, it shows following error when we do the record deletion.
Microsoft jscript runtime error
Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range.
Must be non-negative and less than the size of the collection.
But, it works in .NET 2.0 and we can insert & modify record successfully.
switch (e.CommandName)
{
case "Edit":
{
...
}
case "Delete":
{
int total = 0, done = 0;
foreach (GridViewRow gvr in gvwList.Rows)
{
if ((gvr.Cells[0].FindControl("cbRemoval") as CheckBox).Checked)
{
done += Dir.Delete(decimal.Parse((gvr.Cells[1].FindControl("imbViewDetail") as ImageButton).CommandArgument));
total++;
}
}
sb.Length = 0;
ltlMessage.Text = sb.AppendFormat("(Deleted record(s): {0} of {1} )", done, total).ToString();
break;
}
}
Here is our delete code. After my checking, no error is found in this delete method. However, after exit this gvwList_RowCommand(). it throws error .NET 4.5 and we still cannot find out the problem. What's more, our record is already deleted after our checking.
After checking, the error is thrown in here ScriptResource.axd:
function Sys$WebForms$PageRequestManager$_endPostBack(error, executor, data) {
if (this._request === executor.get_webRequest()) {
this._processingRequest = false;
this._additionalInput = null;
this._request = null;
}
var handler = this._get_eventHandlerList().getHandler("endRequest");
var errorHandled = false;
if (handler) {
var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
handler(this, eventArgs);
errorHandled = eventArgs.get_errorHandled();
}
if (error && !errorHandled) {
throw error;
}
}
An error is passed in this function:
Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index
Phinehas
Member
361 Points
238 Posts
Index out of range in .NET 4.5
Jan 18, 2013 06:30 AM|LINK
Hi,
We have a project that use in .NET 2.0 and it works. However, when we upgrade it to .NET 4.5, it shows following error when we do the record deletion.
Microsoft jscript runtime error
Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range.
Must be non-negative and less than the size of the collection.
But, it works in .NET 2.0 and we can insert & modify record successfully.
Can anyone help us to solve this problem?
urenjoy
Star
11997 Points
1797 Posts
Re: Index out of range in .NET 4.5
Jan 18, 2013 06:43 AM|LINK
please post your delete code here
Phinehas
Member
361 Points
238 Posts
Re: Index out of range in .NET 4.5
Jan 18, 2013 08:05 AM|LINK
switch (e.CommandName) { case "Edit": { ... } case "Delete": { int total = 0, done = 0; foreach (GridViewRow gvr in gvwList.Rows) { if ((gvr.Cells[0].FindControl("cbRemoval") as CheckBox).Checked) { done += Dir.Delete(decimal.Parse((gvr.Cells[1].FindControl("imbViewDetail") as ImageButton).CommandArgument)); total++; } } sb.Length = 0; ltlMessage.Text = sb.AppendFormat("(Deleted record(s): {0} of {1} )", done, total).ToString(); break; } }Here is our delete code. After my checking, no error is found in this delete method. However, after exit this gvwList_RowCommand(). it throws error .NET 4.5 and we still cannot find out the problem. What's more, our record is already deleted after our checking.
All these is work in .NET 2.0.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Index out of range in .NET 4.5
Jan 20, 2013 12:30 AM|LINK
Can you debug your app by pressing F5 and then tell us at which statement the error is thrown out?
Phinehas
Member
361 Points
238 Posts
Re: Index out of range in .NET 4.5
Jan 20, 2013 11:46 PM|LINK
After checking, the error is thrown in here ScriptResource.axd:
function Sys$WebForms$PageRequestManager$_endPostBack(error, executor, data) { if (this._request === executor.get_webRequest()) { this._processingRequest = false; this._additionalInput = null; this._request = null; } var handler = this._get_eventHandlerList().getHandler("endRequest"); var errorHandled = false; if (handler) { var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor); handler(this, eventArgs); errorHandled = eventArgs.get_errorHandled(); } if (error && !errorHandled) { throw error; } }An error is passed in this function:
Sys.WebForms.PageRequestManagerServerErrorException: Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index
Yanping Wang...
Star
14859 Points
1525 Posts
Microsoft
Re: Index out of range in .NET 4.5
Jan 21, 2013 06:28 AM|LINK
Hi Phinehas,
error: Index out of range,
It seem the index value is greater than the valid number in your collecions in "Delete" method.
Please check if the value of gvr.Cells[0].FindControl("cbRemoval"), gvr.Cells[1].FindControl("imbViewDetail") avaliable.
thanks.
Feedback to us
Develop and promote your apps in Windows Store
Phinehas
Member
361 Points
238 Posts
Re: Index out of range in .NET 4.5
Jan 21, 2013 07:38 AM|LINK
This statement is correctly.
In debug mode, it does not throw any exception. The exception I caught is thrown after it exits this function.
And the record is already deleted in database. All processes are done well but don't know why it throws exception.
chetan.sarod...
All-Star
65619 Points
11118 Posts
Re: Index out of range in .NET 4.5
Jan 22, 2013 02:24 AM|LINK
Refer this
http://forums.asp.net/t/1472001.aspx/1
http://forums.asp.net/t/1494430.aspx
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Phinehas
Member
361 Points
238 Posts
Re: Index out of range in .NET 4.5
Jan 23, 2013 01:11 AM|LINK
Not worked at all.
Now, it can only run in .NET 3.5 without any error message thrown.
Why it throws error in .NET 4.0 or above? What's difference between them?