We are trying to allow users to scan documents using a Silverlight XAP running in-browser with elevated trust, from a remote server, and are getting the following error:
Unhandled Error in Silverlight Application Failed to create an object instance for the specified ProgID.
The failure is at the following line:
Dim CommonDialog = AutomationFactory.CreateObject("WIA.CommonDialog")
Application.Current.HasElevatedPermissions and AutomationFactory.IsAvailable both return True.
I can successfully create an instance of unsafe ActiveX controls, e.g. Scripting.FileSystemObject
:
Dim fso = AutomationFactory.CreateObject("Scripting.FileSystemObject")
The code fails when running from the production environment on the remote server. When running from the ASP.NET Development server from localhost, the code succeeds, and the WIA scanning dialog is shown when calling CommonDialog.ShowAcquireImage()
.
How can I resolve this? (Is there perhaps something specific about WIA that prevents it from being used this way?) What steps can I take to try and debug this?
Update
When I try to open the generated Silverlight test page (via the file
protocol), I get the same error.
Update 2
Process Monitor shows that the AllowLaunchOfElevatedTrustApps
and AllowElevatedTrustAppsInBrowser
keys are being successfully queried.
Update 3
With Protected Mode turned off, the code works.
The MSDN reference states that to enable COM Interop inside the browser, you must
Set Registry Key
HKEY_LOCAL_MACHINE\Software\Microsoft\Silverlight\
(or on x64HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Silverlight\
) AllowElevatedTrustAppsInBrowserDWORD
0x0000001
Check your group policy has not disabled
AllowInstallOfElevatedTrustApps
andAllowLaunchOfElevatedTrustApps
Sign the .xap
Install cert to Trusted Application Store (see screenshots illustrating how)
Additionally, you must
configure as Out of Browser Application (even if you are not running Out of Browser)
before calling the
ComAutomationFactory.CreateObject
you should check forApplication.Current.HasElevatedPermissions
andAutomationFactory.IsAvailable
note that Elevated Permission testing from http://localhost and http://127.0.0.1 is not reliable test, as Silverlight runtime makes exception for these two URLs. Instead use
file://
.Troubleshooting
Use ProcMon to verify that the
AllowElevatedTrustAppsInBrowser
registry key is being readAttach Debugger to Silverlight (see screenshots)
MSIE Protected Mode settings can also adversely affect whether a Silverlight application can run with Elevated Permissions. Try running with different Protected Mode settings.