Problem is that: I run this code (CODE 1), and thne gain System.InvalidCastException in browser (ASP.NET). The very same code (in my case I use this function from my another project), running in another project and working with the same data works fine and doesn't throw any exceptions.
I tried to catch this exception and look inside of problem object (CODE 2), but then I was surprised that no exceptions were caught (I placed a break point on second line of a catch code block to be sure) and I got right output in browser
CODE 1
private static List<Dictionary<string, object>> GetResultRows(SQLiteDataReader Reader)
{
List<Dictionary<string, object>> Result = new List<Dictionary<string, object>>();
if (!Reader.HasRows) return Result;
while (Reader.Read())
{
var CurrentRow = new Dictionary<string, object>();
Result.Add(CurrentRow);
for (int i = 0; i < Reader.FieldCount; i++)
{
CurrentRow.Add(Reader.GetName(i), Reader.GetString(i));
}
}
return Result;
}
CODE 2
private static List<Dictionary<string, object>> GetResultRows(SQLiteDataReader Reader)
{
List<Dictionary<string, object>> Result = new List<Dictionary<string, object>>();
if (!Reader.HasRows) return Result;
while (Reader.Read())
{
var CurrentRow = new Dictionary<string, object>();
Result.Add(CurrentRow);
for (int i = 0; i < Reader.FieldCount; i++)
{
//CurrentRow.Add(Reader.GetName(i), Reader.GetString(i));
try
{
CurrentRow.Add(Reader.GetName(i), Reader.GetString(i));
}
catch
{
var temp = Reader.GetValue(i);
System.Diagnostics.Debug.WriteLine($"{Reader.GetName(i)} = {Reader.GetValue(i)}");
}
}
}
return Result;
}
I want this function to be as quick as it can be, so try-catch can't solve my problem. Any ideas?
UPD: Browser exception: image