SubSonic throwing 'System.IndexOutOfRangeException' when in Visual Studio Debug mode
I recently inherited the code set for a Product I now开发者_如何学JAVA own which uses Subsonic 2.1.0 to perform its data-access.
When I go in to debug said code set, all that I get in the Output window of Visual Studio 2010 is the following (for pretty much every column of every object trying to be loaded):
A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll
This is the block of code where it is blowing up in Subsonic, which is located in the SubSonic.RecordBase class, which looks like so:
/// <summary>
/// Loads the object with the current reader's values. Assumes the reader is already moved to
/// first position in recordset (aka has been "Read()")
/// </summary>
/// <param name="dataReader">The data reader.</param>
public virtual void Load(IDataReader dataReader)
{
foreach(TableSchema.TableColumn col in BaseSchema.Columns)
{
try
{
SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);
}
catch(Exception)
{
// turning off the Exception for now
// to support partial loads
// throw new Exception("Unable to set column value for " + col.ColumnName + ": " + x.Message);
}
}
SetLoadState();
MarkClean();
}
The offending line in there is:
SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);
col.ColumnName doesn't match anything in the dataReader at this point. It's almost like it's using an old/prior dataReader to attempt to pull data from.
I'm hoping someone else has encountered this issue, as I'm still fairly new to Subsonic and have only used Hibernate in the past for an ORM.
This happens on both my older machine and a new one I just built, both running Windows 7 Professional x64 w/ Visual Studio 2010 Professional as the IDE.
I've gone through the forums, Google, and many other sites out there, but have yet to find anyone else encountering this issue.
If more information is required, please let me know and I'll be happy to post!
Thanks in advance!
- Justin
After spending a while longer looking into this issue, I've realized that it's intentionally throwing these Exceptions for the sake of "partially loading" a data object when only certain fields are being retrieved from the database and mapped to the data object itself. (e.g. just supresses the Exceptions itself and resumes if it can't map a column's data properly.
Not sure if this was originally part of the SubSonic code or something that was introduced by those before me.
Thanks again!
Justin
It looks like the DB Schema may have changed since the SubSonic objects where last created.
精彩评论