View on GitHub

SARAFF SOFTWARE

All products / Saraff.TwainX.Extensions

Troubleshooting

No data sources

XDsm.DataSources is empty or contains only sources that cannot be opened.

InvalidOperationException: DSM don't open.

XDsm.TwainX calls OpenDSM() and throws when it returns false. Typical causes:

Check the DSM installation and bitness first. If the application needs an explicit DSM path, set it on the underlying TwainX before the first access.

TwainException: DS don't supported TWAIN 2.x specification.

Saraff.TwainX requires a DS2 data source. The source was loaded through a TWAIN 1.x DSM or is not TWAIN 2.x compatible. Use a DS2 driver, or use the Windows Saraff.Twain product for TWAIN 1.x.

XDs.IsTwain2Compatible queries the source without opening it, so it can be used to filter the source list.

InvalidOperationException: An acquisition is already running on this DSM.

The extensions allow only one active transfer per XDsm.

Two AcquireAsync calls on the same XDsm are serialized: the second waits for the first. Two synchronous calls are rejected immediately.

InvalidOperationException when switching sources

The underlying TwainX throws when SourceIndex is assigned while a data source is open and enabled. XDs.TwainX tries to close the previous source first, but cannot close an enabled source.

Finish or cancel the current acquisition before using another XDs, or create a separate XDsm for the other source. The TWAIN DSM is process-wide, so serializing acquisitions is still required.

ObjectDisposedException

The manager has been disposed:

Dispose XDsm only when the form/window or service is finished. Do not use a short using block around an acquisition that continues asynchronously.

InvalidCastException from a capability

The requested T does not match the TWAIN capability type, or the value cannot be converted.

// Wrong: XResolution is a floating-point capability.
var resolution = source.GetCapability<int>(TwCap.XResolution);

// Correct:
var resolution = source.GetCapability<float>(TwCap.XResolution);

The exception message names the source and target types. Enum values can be read as numbers or strings, but an arbitrary object cannot be converted to an enum or a numeric type.

null is valid for reference types and Nullable<T>; it throws for non-nullable value types.

Async acquisition is cancelled

AcquireAsync throws OperationCanceledException/TaskCanceledException when:

Catch OperationCanceledException separately from real TWAIN errors. A pre-cancelled token fails before any DSM or hardware access.

Async acquisition returns no pages

MaxImages must be positive when set. Use null for no limit.

Thread affinity errors

Saraff.TwainX session objects are thread-affine. Synchronous calls must run on the thread that opened the DSM. In WinForms/WPF use the UI/STA thread and a message loop; do not call synchronous transfer helpers from a worker thread.

XDs.AcquireAsync avoids this by creating a dedicated session thread. Its configure and progress callbacks run on that thread. Marshal UI updates to the dispatcher/synchronization context.

Package conflicts

Do not reference both Saraff.TwainX.NET and Saraff.TwainX. Both packages ship Saraff.TwainX.dll; duplicate assemblies cause load errors or unexpected type identities.

Saraff.Twain.Extensions is a different product. Do not mix Saraff.Twain and Saraff.TwainX types in the same project; their Twain32/TwainX APIs and image models are not interchangeable.

Async options do not apply

XDs.AcquireAsync creates its own TwainX session. Language and Country from XDsm.Create(...) are not copied. Use TwainXAcquireOptions for ShowUI, ModalUI, Parent, DsmPath, MaxImages and DisableAfterAcquire, and the configure callback for capabilities.

If options is null, only ShowUI is taken from the manager’s TwainX; all other options use their defaults.

Integration tests

Unit tests do not require a scanner. They cover conversion, enumeration, validation, transfer context guards, disposal and pre-cancelled async calls. Real acquisition needs a TWAIN 2.x DSM and a DS2 source and should be tested manually or in a dedicated hardware test environment.