Invoke or BeginInvoke cannot be called on a control

Class library usage, coding and language questions.
PeterM
Posts: 9
Joined: Mon Jan 16, 2012 11:52 am

Invoke or BeginInvoke cannot be called on a control

Post by PeterM » Mon Feb 17, 2014 6:36 pm

Dear Support!

I have 1 Ranorex solution containing several projects. Since I wanted to have the projects executed one after the other and having 1 report for all, I did what was suggested here on the forum, created a new project which call each projects' Program.Main.
Everything seems to be ok, except that from time to time, I receive the below error in Teamcity log:
"Invoke or BeginInvoke cannot be called on a control until the window handle has been created."

After some minor debugging, it turns out that the problem is in this built in line which calls/starts the test suite of the given project:
error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);

I included some debug messages in the tests, and it seems that the error comes at this point, however, it does not reach the 1st test in the test suite, so the error is coming somewhere between the call and the 1st test case in the suite.

Have you faced such issue may be?
Do you have some information on what this TestSuiteRunner.Run calls first in the background?
We'd like to narrow down the search where the issue might be as it might come on our side as well, but we'd like to be sure first that everything is fine on Ranorex side.
So, have someone faced similar error?

Thank you in advance
Peter

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Invoke or BeginInvoke cannot be called on a control

Post by Support Team » Tue Feb 18, 2014 4:43 pm

Hello Peter,

Is it possible to provide the code from the program.cs file or at least a code snippet how your call of the projects within your “Main”-solution looks like?

Which Ranorex version do you use?

Regards,
Robert

PeterM
Posts: 9
Joined: Mon Jan 16, 2012 11:52 am

Re: Invoke or BeginInvoke cannot be called on a control

Post by PeterM » Wed Feb 19, 2014 4:21 pm

Hi Robert,

Please find it below:

We are using Ranorex 4.1.4.
We are executing the tests via TeamCity. (Applied the integration notes posted here:
http://www.ranorex.com/blog/integrating ... ci-process) and we have a custom logger, also based on the guidance of Ranorex.
And as mentioned, in general, everything is ok.
Except from time to time, the 2nd and forthcoming projects are not executed, we get that invoke error instead.
Its probably on our side, however since the error is coming when we call the TestSuiteRunner in the 2nd project, may be its not that straightforward.
Also, the multiple project call is based on a previous entry:
http://www.ranorex.com/forum/execute-mu ... t5138.html
Please let me know if you can reproduce such behavior, we are also investigating our parts what might be wrong.


Thank you in advance
Peter

class Program
{
[STAThread]
public static int Main(string[] args)
{
// Uncomment the following 2 lines if you want to automate Windows apps
// by starting the test executable directly
//if (Util.IsRestartRequiredForWinAppAccess)
// return Util.RestartWithUiAccess();

Report.AttachLogger(new TeamCity());

Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
int error = 0;

Report.Setup(ReportLevel.Info, "RanorexReport.html", true);

try
{
TestProject1.Program.Main(null);
TestProject2.Program.Main(null);
TestProject3.Program.Main(null);
...

TestProjectX.Program.Main(null);
}
catch (Exception e)
{
Report.Error("Unexpected exception occurred: " + e.ToString());
error = -1;
}
return error;
}
}
}

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Invoke or BeginInvoke cannot be called on a control

Post by Support Team » Mon Feb 24, 2014 4:26 pm

Hi PeterM,

Unfortunately we are not able to reproduce your issue and it’s pretty hard to analyze an issue which occurs only sporadically. It would be great if you could determine when the issue occurs. In what state is the test run? Which programs are opened and so forth?

Thank you for your understanding and thank you in advance.

Regards,
Robert