strange excepstion

I've an app that have been written in vs 2003, today I convert it to vs 2005 but when I want to run this program (in debug mode or not) this exception occurred.
Ex.Message: "DragDrop registration did not succeed."
What's wrong in my app that cause this exception



Answer this question

strange excepstion

  • mcoulton

    I'm getting the same problem in a VB.NET application.  It works fine in vs 2003, but in vs 2005 I get "DragDrop registration did not succeed".  I marked the main method <STATThread()> but that doesn't seem to help.  When I disable DragDrop on my control, the application loads successfully.  Any other ideas
  • wpvanv

    Nice, it actually works!!!



  • Peter D. Falco Jr.

    I have been searching to find an answer on this same question and I just did. 

     

    I read:  http://blogs.msdn.com/adam_nathan/archive/2003/07/18/56727.aspx

    and this gave me a clue.

     

    To solve my problem, I went into the

    Project Properties->Configuration Properties->Linker->Advanced

    and set CLR Thread Attribute to -> STA Threading.

    I thought this was already set by looking at my Form1.cpp file which had STA threading set.

     

    Hope this helps.

    Clark


  • espenhjo

    Has anyone face this exception


  • Josh Korn at Diligentsia

    Tongue Tied
  • Deutschland vor&amp;#33;

    Include the following lines and I hope it will be helpful

    1. at starting,

    using System.Net;

    2. Just before Main()

    [STAThread]
    static void Main()

    Enjoy,




  • Jeremy Riley



    Please do the following,

    1) include the following
    using System.Net;
    using System.Threading;

    2) add the [STAThread] Attribute just before ur main function and also remember to inlcude using System.Net; in ur main program,

    [STAThread]
    static void Main()

    3) The steps are as follows for threading,

    1. Put all the code ( for which u r getting this exception) in one function say function A. In the function B in which u are calling ur code,do the following,
    function B
    {
    Thread t = new Thread(new ThreadStart(A));
    t.SetApartmentState(ApartmentState.STA);
    t.Start( );
    }
    function A
    {
    the code of Windows form..or whatever which is causing the error
    }

    Explanation:
    It turns out that WF when executing all of its pretty pictures creates a thread to run each of those pictures with. These threads are in MTA mode (multi threaded apartments) and thus, in .Net 2.0 cannot be used for forms with drag and drop. so, any code which has AllowDrop Property true will give this error. With this came the following solution. All of the code used to create the form was placed in a single static function. The parent function, when it desires to call a new form ( windows form) , creates a thread, in STA mode, to execute this function. Thus the following code goes in the parent function
    Thread t = new Thread(new ThreadStart(FormFunction));
    t.SetApartmentState(ApartmentState.STA);
    t.Start( );

    I hope this will help.
    Enjoy,
    Sneha

  • strange excepstion