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

0

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://127.0.0.1:8085/'); 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 **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1590.0 built by: NETFXREL2
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
TarasolEdgeScanner
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/e3247/AppData/Local/Apps/2.0/ZHMO22OM.MEP/QOR9B6AK.G6W/tara..tion_0000000000000000_0001.0000_398fd06fc95c8a15/TarasolEdgeScanner.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
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
----------------------------------------
System
Assembly Version: 4.0.0.0
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
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
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
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
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
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
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
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
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
----------------------------------------
Interop.WIA
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
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
enabled.

For example:

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

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)
{
continue;
}

firstScannerAvailable = deviceManager.DeviceInfos[i];

break;
}

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

// 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);
c#
asp.net
websocket
wia
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