Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I had to complete an online test for my local court where I was given the website, a user ID, and a password. After clicking submit, this error popped up: Server Error in '/' Application.

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.]
   System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) +12643268
   System.String.Format(IFormatProvider provider, String format, Object[] args) +123
   System.Web.UI.WebControls.HyperLinkField.FormatDataNavigateUrlValue(Object[] dataUrlValues) +171
   System.Web.UI.WebControls.HyperLinkField.OnDataBindField(Object sender, EventArgs e) +854
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +304
   System.Web.UI.Control.DataBindChildren() +11330983
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
   System.Web.UI.Control.DataBindChildren() +11330983
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +321
   System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +287
   System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +4572
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +94
   System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +18
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +182
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +274
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +183
   System.Web.UI.Control.EnsureChildControls() +182
   System.Web.UI.Control.PreRenderRecursiveInternal() +60
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Control.PreRenderRecursiveInternal() +222
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4185

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.504
Posted
Updated 1-Sep-15 15:49pm
v2
Comments
DamithSL 1-Sep-15 21:56pm    
How you did the data binding? Please update the question with related code

1 solution

In your call to StringBuilder.AppendFormat you have a String format which contains things like {0} {1} , etc. The numbers refer to the index of the value parameters provided. But, chances are, you refer to some {x} which doesn't have a matching value.

This is often due to the braces in the format string that aren't supposed to be replaced by a value -- if this is the case then double the braces {{x}} so it won't cause trouble.
Otherwise, please use Improve question to add the StringBuilder.AppendFormat statement to your question so we can take a look.
If you don't see the format string, then use the debugger to see it.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Sep-15 23:03pm    
Unfortunately, you encourage the inquirers to show exception stack without showing code sample throwing that exception, which is usually ridiculous. But your explanation deserves a 5.
—SA
PIEBALDconsult 2-Sep-15 0:04am    
The stack was already there.
Sergey Alexandrovich Kryukov 2-Sep-15 0:39am    
This is what I say: stack is there, code is missing.
—SA
PIEBALDconsult 2-Sep-15 0:41am    
Yes. It was that way when I first saw it. It hasn't changed. I added pre tags.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900