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

Saraff.Twain.TwainException It worked!

Apr 24, 2015 at 3:15 PM

I am not sure about the actual reason for the Exception below. Could you please help me with it?

Saraff.Twain.TwainException It worked!
at Saraff.Twain.Twain32._GetAllSorces()
at Saraff.Twain.Twain32.OpenDSM()

When I use your library on my development machine there is no issues with OpenDSM() method. But when I tried it on a clean virtual machine I caught the error above.

Do you have any thoughts or suggestions about it?

Thanks in advance!

Apr 24, 2015 at 6:17 PM
Hello, GennadyBaranov.
For more info write value of the TwainException.ReturnCode.
Apr 27, 2015 at 6:44 AM
Edited Apr 28, 2015 at 1:45 PM
Hi Saraff,

ReturnCode = Failure.

By the way, I have tried your sample apps. They are also failing with the same error on virtual machine and working well on my development PC.

I think I was able to find out the reason. Please find my thoughts below:
  1. I have just installed drivers for my scanner to the virtual machine but have never attached device. So, I am getting the exception described in my previous post. The following lines from your library which are throwing exception(OpenDSM -> _GetAllSorces Method):
       for(TwRC _rc=this._dsmEntry.DsmInvoke(this._AppId,TwDG.Control,TwDAT.Identity,TwMSG.GetFirst,ref _item); _rc!=TwRC.Success&&_rc!=TwRC.EndOfList; ) {
            throw new TwainException(this._GetTwainStatus(),_rc);
  2. After I have attached the device, the library works well. It shows 2 "devices" - my scanner and the same one but with WIA interface.
  3. Note, that If I detach device it also works well, shows me my scanner as offline device, so I can manage this situation. So, this error is observed only before first device attach.
So, the main question is this exception thrown in OpenDSM(_GetAllSorces) related to the driver manufacturer or Saraff.Twain.Net really throws such error when we try to initialize Data Source Manager but have not attached devices instead of just having empty sources collection? What do you think?

Apr 28, 2015 at 5:21 PM
Hello, GennadyBaranov.
I think it's a problem of a TWAIN drivers (DSM), as:





The application may obtain a list of all Sources that are currently available on the system which
match the application’s supported groups (DGs, that the application specified in the
SupportedGroups field of its TW_IDENTITY structure). To obtain the complete list of all available
Sources requires invocation of a series of operations. The first operation uses MSG_GETFIRST to
find the first Source on “the list” (whichever Source the Source Manager finds first). All the
following operations use DG_CONTROL / DAT_IDENTITY / MSG_GETNEXT to get the identity
information, one at a time, of all remaining Sources.
If the application wants to cause a specific Source to be opened, one whose ProductName the
application knows, it must first establish the existence of the Source using the MSG_GETFIRST/
MSG_GETNEXT operations. Once the application has verified that the Source is available, it can
request that the Source Manager open the Source using DG_CONTROL / DAT_IDENTITY /
MSG_OPENDS. The application must not execute this operation without first verifying the
existence of the Source because the results may be unpredictable.

Return Codes

    TWCC_NODS /* No Sources can be found */
    TWCC_LOWMEMORY /* Not enough memory to perform this operation */
7-62 TWAIN 2.2 Specification
Marked as answer by SARAFF on 5/6/2015 at 11:30 AM