Scan multiple pages with WIA in C# return HRESULT E_FAIL


  • Hello,


    I try to scan multiple pages with WIA in C# on Windows 10 64 bit Build 17763, the first page work, but the scanner fails for second page and return an error "HRESULT E_FAIL" "System.Runtime.InteropServices.COMException (0x80004005)"

    WIA.CommonDialog dialog = new WIA.CommonDialog();
    Device device = dialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
    Items items = dialog.ShowSelectItems(device);
    foreach (Item item in items)
    	while (true)
    			ImageFile image = (ImageFile)dialog.ShowTransfer(item);
    		catch (COMException ce)

    I tried with some scanners HP and I have the same problem.


    • Edited by pol9595 Friday, January 11, 2019 11:09 PM
    Friday, January 11, 2019 10:58 PM

All replies

  • Why do you have the "while(true)" in there?  After you have transferred an item, you probably don't want to transfer it again and again and again, which is what this code does.  You want to transfer each item once.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Saturday, January 12, 2019 1:52 AM
  • all examples in C# use while(true) for multiple pages scanning

    on stack overflow for example : "Scanning with WIA automatic feeder scanner fails for second page"

    I think Windows Image Acquisition (WIA) has a bug on Windows 10

    • Edited by pol9595 Saturday, January 12, 2019 5:48 PM
    Saturday, January 12, 2019 5:47 PM
  • Hi,

    From this thread, it seems like the ShowTransfer() method was unable to convert the page to .png or .tiff WHILE scanning. Try to set the format to JPEG or BMP to solve the issue:

        ImageFile image = (ImageFile)dialog.ShowTransfer(item, FormatJPEG, false);

    Also please refer to the following similar threads:

    Multipage WIA scan (docfeeder) scans 1 page and blocks scanner

    Scanning with WIA automatic feeder scanner fails for second page



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, January 14, 2019 6:24 AM
  • My code work when I choose in the "device selection dialog / Which device do you want to use?" :"HP scan driver", and doesn't work when I choose "WSD Scan Device".
    • Edited by pol9595 Tuesday, January 15, 2019 9:31 PM
    Tuesday, January 15, 2019 9:31 PM