Coverage : Forms Unit Test > DragDrop registration did not succeed

When running a coverage (commandline) on one of our assemblies the following exception keeps occurring:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidOperationException: DragDrop registration did not succeed. ---> System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
   at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)
   --- End of inner exception stack trace ---
   at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)
   at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
   at System.Windows.Forms.Control.WmCreate(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

This might be due to the thread appartment state of the calling application.
Is it possible to set dotCover to use STA?

Comment actions Permalink


System: Win7 x64, VS2010, NUnit 2.5.10, Resharper 6.1, dotCover 1.2

Running dotCover from IDE does not generate the exception (with NUnit externally configured in Resharper).
It does generate the exception when running command line (with the same NUnit).

Assembly contains app.config:

<?xml version="1.0" encoding="utf-8"?>
    <sectionGroup name="NUnit">
      <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
      <!-- Valid values are STA,MTA. Others ignored. -->
      <add key="ApartmentState" value="STA" />
      <!-- See ThreadPriority enum for other valid values -->
      <add key="ThreadPriority" value="Normal" />

Comment actions Permalink

Hello Pim,
Thank you for the feedback.
I've filed an issue for this our tracker:
You are welcome to track its status.

Comment actions Permalink

Hi Ruslan,

I also created an issue in the tracker for this problem...

Maybe we should remove one of the 2.

Thanks for the reply.

Comment actions Permalink

Sure, I've closed DCVR-3321 as duplicate.

Ekaterina Solovova
Comment actions Permalink

Hello Pim,
I am very sorry for such a long delay!

I have investigated your issue and I guess that dotCover can't be the cause of your problem. It runs NUnit's console in a separate process and doesn't have any influence on its threading model. Please make sure that you have configured your tests and NUnit's console properly. To run tests in STA threads with NUnit 2.5 or newer you can use either configuration file or RequiresSTAAttribute (please see NUnit's documentation on it at If you use configuration file please make sure that it has correct name (assembly_with_tests_name.dll.config) and is placed in the same directory as the assembly with tests at run time. Both configuration file and attribute work fine for me with dotCover 1.2 and 2.0 and NUnit 2.5.10.



Please sign in to leave a comment.