A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll

Topics: Data Access Application Block
Apr 18, 2008 at 2:53 AM
I have a list of cities in my db table. I can't figure out why I get an out of range exception once I step through this method that's called in my DL. I've got around 316 cities:

public static List<City> RetrieveAll()
{
List<City> cityList = new List<City>();
Database db = DatabaseFactory.CreateDatabase();
using (DbCommand cmd = db.GetStoredProcCommand("dbo.CityAllS"))
{
try
{
using (IDataReader reader = db.ExecuteReader(cmd))
{
while (reader.Read())
{
City newCity = new City();
newCity.LoadFromReader(reader);
cityList.Add(newCity);
}
}
}
catch (Exception ex)
{

if (ExceptionPolicy.HandleException(ex, "Elbalazo.DataLayer.Exceptions"))
{
throw;
}
}
}
return cityList;
}

I know that when I get to here, it's showing that there are those records in the reader in its results view:

using (IDataReader reader = db.ExecuteReader(cmd))

but when I get here, I get the exception:

while (reader.Read())

and there's no good error message why other than out of range. But what is out of range and why? I mean a reader can certainly hold more than 316 records one would assume.