Failed to register DragDrop Error

Bug reports.
Posts: 4
Joined: Fri Jun 16, 2017 4:43 pm

Failed to register DragDrop Error

Post by ma.elaallouli » Mon Aug 28, 2017 5:55 pm


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


Posts: 111
Joined: Fri Jul 03, 2015 9:18 am

Re: Failed to register DragDrop Error

Post by jma » Wed Aug 30, 2017 1:10 pm

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: ... =vcgeneral

Concerning the STAThread, please have a look at the following forum discussion: ... t5022.html

I hope that helps!