Page 1 of 1

Failed to register DragDrop Error

Posted: Mon Aug 28, 2017 5:55 pm
by ma.elaallouli
Hello,

I developpe an Ranorex automation project with C# of .NET desktop Application that uses Magics

Sometimes when I run Test case or test suite the dragDrops Exception triggers and block the test.

the exception description is :"System.InvalidOperationException: Failed to register DragDrop. ---> System.Threading.ThreadStateException: The current thread must be in STA mode (Single Thread

Apartment) before OLE calls can be made. Make sure your Main function is marked as STAThreadAttribute."
.

I verify the Main function in "Program.cs and I found it right . the main :
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();

			Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
			int error = 0;
			try
			{
				error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
			}
			catch (Exception e)
			{
				Report.Error("Unexpected exception occurred: " + e.ToString());
				error = -1;
			}
			return error;
		}
	}
Thank you for Helping me

Regards

Re: Failed to register DragDrop Error

Posted: Wed Aug 30, 2017 1:10 pm
by jma
Hi, do you start another thread during test execution? I doubt that this issue is related to Ranorex directly. I found the following discussion in the Microsoft forum: https://social.msdn.microsoft.com/Forum ... =vcgeneral

Concerning the STAThread, please have a look at the following forum discussion: https://www.ranorex.com/forum/where-to- ... t5022.html

I hope that helps!