When trying to access scanner via WIA exception Access is denied (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))


I have a C# Windows application with an integrated scanner running with WebSocket using the command websocketd --port=7777 TarasolEdgeScanner.exe.

I have a ASP.NET web application opening the above windows application using the js command var ws = new WebSocket('ws://'); The application opens normally.

I am using Microsoft Windows imaging Acquisition (WIA) libray to scan the documents in the Windows app. Everything works fine when I open the Windows app alone. But when I open it using the web socket command I get the following exception:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at TarasolEdgeScanner.ScanForm.StartScan()
at TarasolEdgeScanner.ScanForm.btnScan_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
Assembly Version:
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
Assembly Version:
Win32 Version:
CodeBase: file:///C:/Users/e3247/AppData/Local/Apps/2.0/ZHMO22OM.MEP/QOR9B6AK.G6W/tara..tion_0000000000000000_0001.0000_398fd06fc95c8a15/TarasolEdgeScanner.exe
Assembly Version:
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
Assembly Version:
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
Assembly Version:
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
Assembly Version:
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
Assembly Version:
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
Assembly Version:
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
Assembly Version:
Win32 Version:
CodeBase: file:///C:/Users/e3247/AppData/Local/Apps/2.0/ZHMO22OM.MEP/QOR9B6AK.G6W/tara..tion_0000000000000000_0001.0000_398fd06fc95c8a15/Interop.WIA.DLL

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging

For example:

<system.windows.forms jitDebugging="true" />

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

I tried to debug but I failed. It's not debugging. Please help.

The code works well when I run it separately without the ASP.NET form

// Create a DeviceManager instance
var deviceManager = new DeviceManager();

// Create an empty variable to store the scanner instance
DeviceInfo firstScannerAvailable = null;

// Loop through the list of devices to choose the first available
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
// Skip the device if it's not a scanner
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType)

firstScannerAvailable = deviceManager.DeviceInfos[i];


// Show a message and stop if no connected scanners found
if (firstScannerAvailable == null)
MessageBox.Show("No connected scanners found!");

// Connect to the first available scanner
var device = firstScannerAvailable.Connect();

// Select the scanner
var scannerItem = device.Items[1];
// Retrieve an image in JPEG format and store it into a variable
//var imageFile = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatJPEG); //This scans without showing progress
CommonDialogClass dlg = new CommonDialogClass(); //To show scanning progress
//The exception raised in below line
object scanResult = dlg.ShowTransfer(scannerItem, WIA.FormatID.wiaFormatJPEG, false);
asked on Stack Overflow Apr 16, 2019 by Mostafa Wahbi • edited Apr 16, 2019 by Mostafa Wahbi

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0