This code has worked consistently since its implementation, but after updating Ranorex to v. 5.2.x I've received the error "Failed to set value'' to variable 'queryData'. String was not recognized as a valid List`1.' when running my code to retrieve a List<List<string>>, and the stacktrace shows the error is being thrown from Ranorex.Core.Data.ReflectionDataProvider.SetValue method (full stacktrace posted below).
Any idea why this is happening now and how it can be rectified? Many of our test cases make use of obtaining a list of data from the database and passing it to our test cases for validation. Thank you!
Stacktrace:
Code to retrieve List<List<string>> from MySQL database:at Ranorex.Core.Data.ReflectionDataProvider.SetValue(CaseInsensitiveString variableName, String value, Boolean exceptionOnFail) at Ranorex.Core.Data.ReflectionDataProvider.SetValue(CaseInsensitiveString variableName, String value) at Ranorex.Core.Testing.TestSuiteModule.RunInternal(DataContext parentDataContext)
Code: Select all
public static List<List<string>> GetSQLData(string query, int length)
{
string connStr = "SERVER=localhost;" +
"DATABASE=xxxxxxx;" +
"UID=xxxxxxx;" +
"PWD=xxxxxxx;" +
"Allow Zero Datetime=true;" +
"Allow User Variables=true;";
MySqlConnection conn = new MySqlConnection(connStr);
MySqlDataAdapter data = new MySqlDataAdapter();
MySqlCommand command = conn.CreateCommand();
command.CommandText = query;
DataSet resultsDataSet = new DataSet();
resultsDataSet.Clear();
conn.Open();
List<List<string>> resultList = new List<List<string>>();
try{
MySqlDataAdapter dataAdapter = new MySqlDataAdapter(command);
dataAdapter.Fill(resultsDataSet);
foreach(DataRow resultRow in resultsDataSet.Tables[0].Rows)
{
List<string> innerResultList = new List<string>();
for(int i = 0; i<resultRow.ItemArray.Length;i++)
{
string result = "";
if(string.IsNullOrEmpty(resultRow.ItemArray[i].ToString()))
{
result = "";
}else{
//Remove all whitespace for more accurate validation
result = resultRow.ItemArray[i].ToString();
//Trim strings longer than the # of chars specified
if(result.Length > length)
{
result = result.Substring(0,length);
}
}
innerResultList.Add(result);
}
resultList.Add(innerResultList);
}
Report.Log(ReportLevel.Info, "Query result rows: " + resultList.Count.ToString());
Report.Log(ReportLevel.Info, "Query result columns: " + resultList[0].Count.ToString());
}
finally
{
conn.Close();
}
return resultList;
}