Failed to set value '' to variable 'xxxxx'

Class library usage, coding and language questions.
kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Failed to set value '' to variable 'xxxxx'

Post by kmck » Fri Jan 16, 2015 5:16 pm

I have user code that accesses data from a MySQL database and returns table data as a List<List<string>> variable (All code posted below).

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:
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 to retrieve List<List<string>> from MySQL database:

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;
        }

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Failed to set value '' to variable 'xxxxx'

Post by krstcs » Fri Jan 16, 2015 5:38 pm

Have you thought about using a .NET DataTable instead of a list<list<string>>? It is usually much easier to work with and can be filled directly from MySQL's DataAdapter.

You then get a table with rows and columns. Each row would then have a collection of items corresponding to the columns. And the types for each cell would match the type in the DB so you wouldn't need to convert from strings.
Shortcuts usually aren't...

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Failed to set value '' to variable 'xxxxx'

Post by kmck » Fri Jan 16, 2015 5:55 pm

I wouldn't be opposed to that, but I'm afraid it would require a massive overhaul at this point that we really can't do just yet. The way our modules interact with one another rely on using List<List<string>> variables. Surely there is something else we can implement into our code to get it to work the way it has for all other previous versions? I hope?

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Failed to set value '' to variable 'xxxxx'

Post by kmck » Tue Jan 20, 2015 5:36 pm

Anyone else have this issue and were able to implement a workaround? Anyone from the Ranorex team have some insight?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Failed to set value '' to variable 'xxxxx'

Post by Support Team » Wed Jan 21, 2015 12:45 pm

Hello kmck,

I’ve created a sample project using your code in order to retrieve data from the database (SQLServer) and did not face any issues. Therefore, I assume that your issue is not caused from the mentioned code. It would be great if you could give us more information about further processing of the “List<List<string>>” variable.

Regards,
Robert
.
Image

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Failed to set value '' to variable 'xxxxx'

Post by kmck » Wed Jan 21, 2015 6:26 pm

Hello Robert,

Thank you for your response.

The way I have it currently set up is the code to retrieve data from our MySQL database is segregated into a code module called SQLMethods in a Class Library titled SharedMethods.

In SharedMethods, I created a recording module called Run_SQL_Query_List that accesses the GetSQLData() method from the SQLMethods code module and has a parameter where the SQL query can be passed to the recording module via a variable.

When I run the SQLMethods code module it works fine. Same for when I run Run_SQL_Query_List directly from SharedMethods. However, when referencing the SharedMethods library from another project and drag and drop the Run_SQL_Query_List module into the test case is where aforementioned error occurs. The strange part is if I create a code module in the project that references SharedMethods and have that code module run Run_SQL_Query_List within it, it also works fine.

So in short, it seems that it only does not work when I have GetSQLData() code being accessed from a recording module that is dragged and dropped into a project's test case from the referenced SharedMethods library. Any reason why this would all of a sudden occur with 5.2.X?

Thank you in advance.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Failed to set value '' to variable 'xxxxx'

Post by Support Team » Fri Jan 23, 2015 1:27 pm

Hello kmck,

Unfortunately, we are not able to reproduce this issue. May I ask you to send your Ranorex solution to [email protected]? This would help us in analyzing your issue in more detail.

Thank you in advance.

Regards,
Robert
.
Image

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Failed to set value '' to variable 'xxxxx'

Post by kmck » Fri Jan 23, 2015 4:02 pm

Hello Robert,

Thank you, I went ahead and sent the sample project and corresponding sample library with the code in question to support.

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Failed to set value '' to variable 'xxxxx'

Post by kmck » Wed Feb 11, 2015 5:43 pm

For anyone else who might stumble across this problem, Robert and Bernhard were able to provide me with a workaround in the interim while we update our code.

TestVariable in Ranorex is only equipped to pass string values, however you can pass List<List<string>> objects by opening up your data binding and setting the parameter value that holds the List<List<string>> variable to the following and it will pass the data between modules:

Code: Select all

AAEAAAD/////AQAAAAAAAAAEAQAAAPEBU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuTGlzdGAx
W1tTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYy5MaXN0YDFbW1N5c3RlbS5TdHJpbmcsIG1zY29y
bGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjc3
YTVjNTYxOTM0ZTA4OV1dLCBtc2NvcmxpYiwgVmVyc2lvbj0yLjAuMC4wLCBDdWx0dXJlPW5ldXRy
YWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQMAAAAGX2l0ZW1zBV9zaXplCF92
ZXJzaW9uAwAAgQFTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYy5MaXN0YDFbW1N5c3RlbS5TdHJp
bmcsIG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5
VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OV1dW10ICAkCAAAAAAAAAAAAAAAHAgAAAAABAAAAAAAAAAN/
U3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWMuTGlzdGAxW1tTeXN0ZW0uU3RyaW5nLCBtc2Nvcmxp
YiwgVmVyc2lvbj0yLjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1
YzU2MTkzNGUwODldXQs=

If you are working with List<string> variables, you can set the value for it in data binding to the following:

Code: Select all

AAEAAAD/////AQAAAAAAAAAEAQAAAH9TeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYy5MaXN0YDFb
W1N5c3RlbS5TdHJpbmcsIG1zY29ybGliLCBWZXJzaW9uPTIuMC4wLjAsIEN1bHR1cmU9bmV1dHJh
bCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OV1dAwAAAAZfaXRlbXMFX3NpemUIX3Zl
cnNpb24GAAAICAkCAAAAAAAAAAAAAAARAgAAAAAAAAAL
databinding.png
databinding.png (17.13 KiB) Viewed 2083 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Failed to set value '' to variable 'xxxxx'

Post by Support Team » Thu Feb 12, 2015 10:43 am

Hello kmck,

Thank you for updating the forum post.

Regards,
Robert
.
Image