System.IndexOutOfRangeException on a webfarm

Here is another issue that a customer had that I thought would be helpful to others.

Problem

The customer said they are getting Exception type: System.IndexOutOfRangeException every minute or so when accessing their web site.  The error looks like:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at System.Web.UI.WebControls.GridView.LoadControlState(Object savedState)
  at System.Web.UI.Control.LoadControlStateInternal(Object savedStateObj)
  at System.Web.UI.Page.LoadAllState()
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Resolution

This is trying to load ViewState.  ViewState is not necessarily compatible between different versions of the runtime, including service pack changes. A given application, even if distributed in a web farm, must be running on the same exact runtime version on all servers.  This includes the bit-ness.  So they all need to be x86 or x64 as on the same version (Service Pack, etc).

Published 13 August 08 06:00 by Tom
Filed under: , , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Ramendra Kumar said on August 27, 2008 3:09 AM:

It gives An Exception for System.IndexOutOfRangeException:

Sql Field IS int also. Could You Help ME

totalsponsoe = Convert.ToInt32(sdr["AppMstSponsorTotal"]);

# Rob Awe said on September 16, 2008 2:19 PM:

There's probably a typo in your field name.

# Tom said on September 16, 2008 2:56 PM:

Good point Rob, remember that the SQL field names are case sensative.

# Ariady Putra said on October 14, 2008 12:35 AM:

my problem is similar to Ramendra  Kumar, but i only get the System.IndexOutOfRangeException if i try to call <b>char</b> or <b>text</b> data type  from SQL. other fields using int or varchar no problem. i've checked over and over the field name.

bceData.Answer = sqlDataReader["AnswerField"].ToString();

the "AnswerField" is <b>text</b> datatype in SQL. can you help me please?

i have no permission to alter the database.

# Ariady Putra said on October 16, 2008 2:51 AM:

alright, please forget my previous comment :D the problem was in the stored procedure :D now everything is solved :D i'm still learning anyway :D

# swapneel said on July 28, 2009 7:16 AM:

sql = "select Rlens_code,Llens_code from Spects where " & oprator & " = '" & Search & "'"

       CM = New SqlCommand(sqlstr, frmMasterObj.cn)

       Dim dr1 As SqlDataReader = CM.ExecuteReader

       If dr1.HasRows = True Then

           While (dr1.Read)

               If dr1("Llens_code") = "" Then

                   lblRtLensRef.Text = ""

               Else

                   lblLtLensRef.Text = dr1("Llns_code").ToString()

               End If

               If dr1("Rlens_code") = "" Then

                   lblLtLensRef.Text = ""

               Else

                   lblRtLensRef.Text = dr1("Rlens_code").ToString()

               End If

           End While

           dr1.Close()

       End If

in this code if some value is null so how can we catch that null value

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker