jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM
Other
856 stars 145 forks source link

System.IndexOutOfRangeException: Index was outside the bounds of the array. #469

Closed fara-ru251 closed 2 years ago

fara-ru251 commented 2 years ago

Hello to All, today I faced the problem "Index was outside the bounds of the array". Stack Trace is below: at Oracle.ManagedDataAccess.Client.OracleDataReader.RetrieveSchemaTable(DataTable& dataTable, Boolean isFromEx) at Oracle.ManagedDataAccess.Client.OracleDataReader.GetSchemaTableCopy(DataTable& dataTable, Boolean isFromEx) at Oracle.ManagedDataAccess.Client.OracleDataReader.GetSchemaTable() at Insight.Database.Providers.OracleManaged.OracleInsightDbProvider.IsXmlColumn(IDataReader reader, Int32 index) at Insight.Database.DbSerializationRule.GetSerializer(IDataReader reader, Int32 column, ClassPropInfo prop) at Insight.Database.ColumnMapping.MapColumn(Type type, IDataReader reader, Int32 column, IColumnMapper overrideMapping) at Insight.Database.ColumnMapping.<>cDisplayClass13_0.b0(Int32 i) at System.Linq.Enumerable.SelectRangeIterator1.ToArray() at Insight.Database.ColumnMapping.MapColumns(Type type, IDataReader reader, Int32 startColumn, Nullable1 columnCount, IColumnMapper overrideMapping) at Insight.Database.CodeGenerator.ClassDeserializerGenerator.MapColumns(Type type, IDataReader reader, Int32 startColumn, Int32 columnCount, IRecordStructure structure, Boolean allowBindChild) at Insight.Database.CodeGenerator.ClassDeserializerGenerator.CreateClassDeserializerDynamicMethod(Type type, IDataReader reader, IRecordStructure structure, Int32 startColumn, Int32 columnCount, Boolean createNewObject, Boolean isRootObject, Boolean allowBindChild, Boolean checkForAllDbNull) at Insight.Database.CodeGenerator.ClassDeserializerGenerator.CreateClassDeserializer(Type type, IDataReader reader, IRecordStructure structure, Int32 startColumn, Int32 columnCount, Boolean createNewObject) at Insight.Database.CodeGenerator.ClassDeserializerGenerator.CreateDeserializer(IDataReader reader, Type type, IRecordStructure structure, SchemaMappingType mappingType) at Insight.Database.CodeGenerator.DbReaderDeserializer.<>cDisplayClass8_0.b0(SchemaMappingIdentity key) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Insight.Database.CodeGenerator.DbReaderDeserializer.GetDeserializer(IDataReader reader, Type type, IRecordStructure structure, SchemaMappingType mappingType) at Insight.Database.CodeGenerator.DbReaderDeserializer.GetDeserializer[T](IDataReader reader, IRecordStructure structure) at Insight.Database.DBReaderExtensions.AsEnumerable[T](IDataReader reader, IRecordReader1 recordReader)+MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Insight.Database.Structure.ListReader1.Read(IDbCommand command, IDataReader reader) at Insight.Database.DBConnectionExtensions.<>c__DisplayClass178_01.b__1(IDbCommand cmd, IDataReader r) at Insight.Database.DBConnectionExtensions.ExecuteAndAutoClose[T](IDbConnection connection, Func2 getCommand, Func3 translate, CommandBehavior commandBehavior) at Insight.Database.DBConnectionExtensions.QuerySql[T1](IDbConnection connection, String sql, Object parameters, CommandBehavior commandBehavior, Nullable`1 commandTimeout, IDbTransaction transaction, Object outputParameters)

The service is running as a BackgroundService worker and constanlty runs without restarting. I tried to reproduce the error, but after restarting service all was fine. Some idea about why this is happened is a cache of table schema saved on service. A day before I added new column to the table from the data was fetched. Another idea is: when I fetching columns from table I used an (asterisk) [SELECT FROM TABLE1 T1 JOIN TABLE2 T1 ON T1.COL1 = T2.COL2], may be problems with mapping table column to POCO object.

Thanks in advance!

Jaxelr commented 2 years ago

It would be really helpful if you provide a bit more context. By that i mean, the class you are trying to map + the specific query?

fara-ru251 commented 2 years ago
var query = @"SELECT
                    *
              FROM
                  TABLE1 T1 
                  JOIN TABLE2 T2 ON T2.FIELD2= T1.FIELD1"; // query used to retrieve data from DB (here I use * (asterisk))

Func<DbConnection, IList<TABLE1MODEL>> tableFunc = new Func<DbConnection, IList<TABLE1MODEL>>((conn) =>
{

  return conn.QuerySql<TABLE1MODEL>(query); // model used to map, appears below "TABLE1MODEL"
});

List<TABLE1MODEL> table1List = null;
using (var conn = this._database.Open())
{
  table1List = tableFunc(conn).ToList(); //  <= here exception is thrown
}

the model I used to map from database tables

public class TABLE1MODEL
{
    public string FIELD1 { get; set; }
    public string FIELD2 { get; set; }
    public string FIELD3 { get; set; }
    public int FIELD4 { get; set; }
    public string FIELD5 { get; set; }
    public DateTime FIELD6 { get; set; }
    public int FIELD7 { get; set; }
    public int FIELD8 { get; set; }
    public string FIELD9 { get; set; }
    public string FIELD10 { get; set; }
    public int FIELD11 { get; set; }
    public string FIELD12 { get; set; }
    public string FIELD13 { get; set; }
    public string FIELD14 { get; set; }
    public string FIELD15 { get; set; }
    public string FIELD16 { get; set; }
    public string FIELD17 { get; set; }
    public string FIELD18 { get; set; }
    public string FIELD19 { get; set; }
    public string FIELD20 { get; set; }
    public string FIELD21 { get; set; }
    public string FIELD22 { get; set; }
    public string FIELD23 { get; set; }
    public string FIELD24 { get; set; }
    protected string SOME_FIELD_NOT_EXISTINDB1 { get; set; } 

    public int SOME_FIELD_NOT_EXISTINDB2 { get; set; }
    public int SOME_FIELD_NOT_EXISTINDB3 { get; set; }
    public string FIELD25 { get; set; }
    public string FIELD26 { get; set; }
    public int FIELD27 { get; set; }
    public int FIELD28 { get; set; }
    public long FIELD29 { get; set; }
    public string FIELD30 { get; set; }

    public List<OtherModel> SOME_FIELD_NOT_EXISTINDB4 { get; set; }
}

TABLE1 table schema looks like this 147723848-77d03b3f-3bfc-4d87-8db6-9ffaf216fac1 TABLE2 table schema as below 147723935-3c968261-edf1-4c22-9de5-030b52245b3d

Here when selecting joined results if our column names is repeating in both tables we have duplicated columns eg. (FIELD1, FIELD1_1), is this may a problem ? May be library has errors in mapping columns when they differ somehow (in count)?

jonwagner commented 2 years ago

Looking at your stack trace:

Stack Trace is below:
at Oracle.ManagedDataAccess.Client.OracleDataReader.RetrieveSchemaTable(DataTable& dataTable, Boolean isFromEx)
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetSchemaTableCopy(DataTable& dataTable, Boolean isFromEx)
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetSchemaTable()

The exception is thrown in the oracle driver, not in Insight.Database. The call to GetSchemaTable() is pretty simple so I don't think it's an issue with Insight.

I'd recommend updating the OracleManagedDataAccess library.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.