The error System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' indicates that you are trying to access an index in an array that does not exist. This is likely happening in the part of the code where you are accessing the elements from the rdr object. It's important to ensure that the index you are accessing is within the bounds of the array.
Here's a revised version of your code that ensures the indices are within the bounds of the array:
private async Task<List<string>> LoadNotes()
{
List<string> notes = new List<string>();
try
{
using (MySqlConnection conn = new MySqlConnection(Constants.connectionString))
{
await conn.OpenAsync();
using (MySqlCommand cmd = new MySqlCommand(Constants.selectAllQuery, conn))
{
using (MySqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
if (!rdr.IsDBNull(0))
{
notes.Add(rdr.GetString(0));
}
if (!rdr.IsDBNull(1))
{
notes.Add(rdr.GetString(1));
}
}
}
}
}
}
catch (MySqlException ex)
{
Console.WriteLine("Error: " + ex.Message);
}
return notes;
}
Make sure, before accessing the data from the reader, we check whether the index is valid and the value is not null using the IsDBNull method. Make sure the indices 0 and 1 correspond to the existing columns in your database. Also, make sure that the data types retrieved match the types you are trying to store in the notes list.