This project has moved. For the latest updates, please go here.

Works only while debugger is attached

Dec 28, 2014 at 11:46 AM
Hi,

First of all, thank you for your " Twain code" , it helps me a lot.

However, I'm facing a very strange behaviour : In my test project, but also in your "sample2 project" , "Acquire()" only works if application is launching from debugger. with CTRL+F5 or in release mode,
"Acquire()" returns : "TwainException: DG DAT MSG out of expected sequence. ConditionCode = SeqError; ReturnCode = Failure;"

Could you help me please ?

Thank you in advance

David
Coordinator
Dec 28, 2014 at 1:47 PM
Hello, DavidM81!
Specify in more detail:
  • platform (x86 or x64);
  • OS
  • version of the Saraff.Twain.NET
  • value of the Twain32.IsTwain2Enable
  • value of the Twain32.IsTwain2Supported (after the Twain32.OpenDSM call)
  • stack trace (of Saraff.Twain.Sample2)
  • have you changed the code of Saraff.Twain.NET or Saraff.Twain.Sample2?
Dec 28, 2014 at 4:13 PM
Edited Dec 28, 2014 at 4:56 PM
platform : X86 (win 2008 64 bits but all my projects have benn compiled in x86, i try with X64 no changes)

OS : Windows 2008 SP1 65 bits

value of the Twain32.IsTwain2Enable = true

value of the Twain32.IsTwain2Supported (after the Twain32.OpenDSM call) = true


stack trace (of Saraff.Twain.Sample2) :
à Saraff.Twain.Twain32._NativeTransferPictures() dans C:\dev\workspace\LCCO-cheque cadeau\SaraffTwain\Saraff.Twain\Twain32.cs:ligne 979
à Saraff.Twain.Twain32._TwCallbackProcCore(TwMSG msg, MethodInvoker endAction) dans C:\dev\workspace\LCCO-cheque cadeau\SaraffTwain\Saraff.Twain\Twain32.cs:ligne 1196
TwainException: DG DAT MSG out of expected sequence. ConditionCode = SeqError; ReturnCode = Failure;


have you changed the code of Saraff.Twain.NET or Saraff.Twain.Sample2? :

Code of Saraff.Twain.NET : NO

Saraff.Twain.Sample2 : YES =>

__I've update this line : this._twain32.SetCap(TwCap.XferCount,-1);

because it failed with "Data Parameter out of range". It works with this._twain32.SetCap(TwCap.XferCount, (short) -1);


I've also noticed a strange thing :

If I start the program in debug mode, then I detach the debugger, program still works !


Hope it can help you
Dec 29, 2014 at 1:54 PM
Hi,

after several tests, it works if i disable Twain2. Fortunately , it seems that I don' need to use version 2

But I'd like to know why twain2 only works with debugger, strange no ?

Have you any idea ?

Thank you

David.
Coordinator
Dec 29, 2014 at 2:43 PM
Hello, DavidM81!
Try following:
  • update Saraff.Twain.NET code to latest version;
  • insert follow line of code before Twain32.Acquire() method:
MessageBox.Show(System.Threading.Thread.CurrentThread.GetApartmentState().ToString(),"Saraff.Twain.Sample2",MessageBoxButtons.OK,MessageBoxIcon.Information);
Dec 29, 2014 at 2:54 PM
The same errors occurs with your latest code (trunk).

The ApartementState is STA

Thank you
Coordinator
Dec 29, 2014 at 3:50 PM
Subscribe to the TwainStateChanged event and write follow code:
private void _twain32_TwainStateChanged(object sender,Twain32.TwainStateEventArgs e) {
    try {
        var _msg=string.Format("TwainStateChanged: {0}\r\n{1}\r\n",e.TwainState,new System.Diagnostics.StackTrace(true).ToString());
        MessageBox.Show(_msg,"Saraff.Twain.Sample2",MessageBoxButtons.OK,MessageBoxIcon.Error);
        Debug.WriteLine(_msg);
    } catch(Exception ex) {
        MessageBox.Show(ex.Message,ex.GetType().Name,MessageBoxButtons.OK,MessageBoxIcon.Error);
        Debug.WriteLine(string.Format("{0}: {1}\n{2}",ex.GetType().Name,ex.Message,ex.StackTrace));
    }
}
and show all messages
Marked as answer by SARAFF on 1/15/2015 at 10:49 AM