none
access violation in thread which invokes unmanaged code with Enable Unmanaged Code debugging checked in RRS feed

  • Question

  • I ran WinForm application which launches thread that calls unmanaged DLL.

    everything works fine (I am getting meaningful results) unless i check-in "Enable Unmanaged Code debugging" in Project properties. Than I am getting access violation in unmanaged code.

    Thread in managed code:

                t = new Test();
                t.done+=new EventHandler<Done>(OnDone);
                SetRunData(t);
                //t.Execute();
                thr = new Thread(new ParameterizedThreadStart(t.Execute));
                int rr = (int)(Convert.ToInt32(this.tb_Time.Text));
                thr.Start(rr);

     

    Execute code:

                int ret = StartPS(ref pF);

               ret = StartProcessingE(pF, ref inp)

               Thread.Sleep((int)sec*1000);

              ret = GetResults(pF, ref res);        

              StopPS(ref pF, "result.txt");

     

    Signatures:

            [DllImport("some.dll")]
            public static extern int StartPS(ref int pInstancePSE);       

            [DllImport("some.dll")]
            public static extern int StartProcessingE(int pInstancePSE, ref PS_INPUT_DATA pInputData);
            [DllImport("some.dll")]
            public static extern int GetResults(int pInstancePSE, ref PS_OUT_DATA pOutData);

     

    Problem is intermittent, in some cases debugger just hangs. Any ideas where to dig?

     

    Thank you

    Monday, February 21, 2011 10:41 PM

Answers

  • I ran WinForm application which launches thread that calls unmanaged DLL.

    everything works fine (I am getting meaningful results) unless i check-in "Enable Unmanaged Code debugging" in Project properties. Than I am getting access violation in unmanaged code.

    Thread in managed code:

                t = new Test();
                t.done+=new EventHandler<Done>(OnDone);
                SetRunData(t);
                //t.Execute();
                thr = new Thread(new ParameterizedThreadStart(t.Execute));
                int rr = (int)(Convert.ToInt32(this.tb_Time.Text));
                thr.Start(rr);

     

    Execute code:

                int ret = StartPS(ref pF);

               ret = StartProcessingE(pF, ref inp)

               Thread.Sleep((int)sec*1000);

              ret = GetResults(pF, ref res);        

              StopPS(ref pF, "result.txt");

     

    Signatures:

            [DllImport("some.dll")]
            public static extern int StartPS(ref int pInstancePSE);       

            [DllImport("some.dll")]
            public static extern int StartProcessingE(int pInstancePSE, ref PS_INPUT_DATA pInputData);
            [DllImport("some.dll")]
            public static extern int GetResults(int pInstancePSE, ref PS_OUT_DATA pOutData);

     

    Problem is intermittent, in some cases debugger just hangs. Any ideas where to dig?

     

    Thank you


    Is this 32-bit or 64-bit? VS2008 or VS2010?

    If you have enabled unmanaged debugging and then in the Exceptions menu (under Debug in the IDE main menu) you set break when raise for unmanaged exceptions, you should get the IDE to take you right to the cause of the unmanaged exception inside the unmanaged src code as soon as the exception arises.

     

    Cap'n

     

    • Marked as answer by eryang Monday, March 7, 2011 3:45 AM
    Friday, February 25, 2011 5:20 PM

All replies

  •  

    May I know on which line your unmanaged code throws an exception? make sure that parameter passed to unmanaged world has been initiated correctly, if you pass any callback function pointer to unmanaged method,  be notice that the managed delegate might be collected during execution of unmanaged code.

     

    See also: CallbackOnCollectedDelegate 


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 22, 2011 7:03 AM
  • I ran WinForm application which launches thread that calls unmanaged DLL.

    everything works fine (I am getting meaningful results) unless i check-in "Enable Unmanaged Code debugging" in Project properties. Than I am getting access violation in unmanaged code.

    Thread in managed code:

                t = new Test();
                t.done+=new EventHandler<Done>(OnDone);
                SetRunData(t);
                //t.Execute();
                thr = new Thread(new ParameterizedThreadStart(t.Execute));
                int rr = (int)(Convert.ToInt32(this.tb_Time.Text));
                thr.Start(rr);

     

    Execute code:

                int ret = StartPS(ref pF);

               ret = StartProcessingE(pF, ref inp)

               Thread.Sleep((int)sec*1000);

              ret = GetResults(pF, ref res);        

              StopPS(ref pF, "result.txt");

     

    Signatures:

            [DllImport("some.dll")]
            public static extern int StartPS(ref int pInstancePSE);       

            [DllImport("some.dll")]
            public static extern int StartProcessingE(int pInstancePSE, ref PS_INPUT_DATA pInputData);
            [DllImport("some.dll")]
            public static extern int GetResults(int pInstancePSE, ref PS_OUT_DATA pOutData);

     

    Problem is intermittent, in some cases debugger just hangs. Any ideas where to dig?

     

    Thank you


    Is this 32-bit or 64-bit? VS2008 or VS2010?

    If you have enabled unmanaged debugging and then in the Exceptions menu (under Debug in the IDE main menu) you set break when raise for unmanaged exceptions, you should get the IDE to take you right to the cause of the unmanaged exception inside the unmanaged src code as soon as the exception arises.

     

    Cap'n

     

    • Marked as answer by eryang Monday, March 7, 2011 3:45 AM
    Friday, February 25, 2011 5:20 PM