System.InvalidOperationException in System.Windows.Forms.dll

Hi!!!

I posted some days ago with a problem: I had this:

I had a large C++ unmanaged application which I compiled and ran perfectly using Visual Studio 2003. Now, I want to compile and run it using Visual Studio 2005.
When I compiled it in release mode everything worked fine, but I got about a thousand comiler errors when trying to compile it in debug mode. All of these compiler errors appear in files that belong to Visual Studio 2005 such as stdlib.h, cstdlib.h,etc.

Finally, I managed to compile my application in debug mode :D

But now when I try to run my application I get this message:

System.InvalidOperationException occurred in System.Windows.Forms.dll

Additional information: DragDropRegistration did not succeed.

Another thing is that I am using Visual Studio 2005 Beta 2, maybe I got this problem because of using this version I’ve asked for the final version but I still don’t have it.

Any suggestion

Thank you very much for your help.



Answer this question

System.InvalidOperationException in System.Windows.Forms.dll

  • Gil tap

    ccoxon wrote:

    I had a large C++ unmanaged application which I compiled and ran perfectly using Visual Studio 2003. Now, I want to compile and run it using Visual Studio 2005.
    When I compiled it in release mode everything worked fine, but I got about a thousand comiler errors when trying to compile it in debug mode. All of these compiler errors appear in files that belong to Visual Studio 2005 such as stdlib.h, cstdlib.h,etc.

    If you used STL instead of C, you wouldn't have got these errors!

    ccoxon wrote:

    System.InvalidOperationException occurred in System.Windows.Forms.dll

    Additional information: DragDropRegistration did not succeed.

    Going from google searches of this error, it sounds like your app initialises COM with the multithreaded apartment model. Drag and drop requires you to use OleInitialize, usable only in the Single threaded apartment model.

    What happens when you change the attribute [MTAThread] (look above your Main) to [STAThread].

    ccoxon wrote:

    Another thing is that I am using Visual Studio 2005 Beta 2, maybe I got this problem because of using this version I’ve asked for the final version but I still don’t have it.

    If delivery took more than a month, you may want to contact the delivery company or reseller for more information.

    In the meantime, you might be able to download the express editions (just to check if it is a Beta 2 bug).



  • Steve Heffern

    Changing the apartmentstate like this no longer works in .NET 2.0:

    In the .NET Framework version 2.0, new threads are initialized as ApartmentState.MTA if their apartment state has not been set before they are started. The main application thread is initialized to ApartmentState.MTA by default. You can no longer set the main application thread to ApartmentState.STA by setting the Thread.ApartmentState property on the first line of code. Use the STAThreadAttribute instead.

    You have to use [STAThread].



  • Miguel Angel Sánchez

    Isn’t it enough setting linker options of the main project  to /CLRTHREADATTRIBUTE:STA
    I’m talking about project properties, configuration properties, linker, advanced, CLR thread attribute.

    Maybe am I missing another option in the project settings

    Again, Thanks very much for all your help :)


  • jphoekstra

    First of all, thank you for your help.

    The first thing is that I already use [STA Thread].

    The first line of my main function is like this:

    System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState STA;

    Any other suggestion

    Thank you so much for your helkp :-)


  • System.InvalidOperationException in System.Windows.Forms.dll