Failed to create an object instance for the specified ProgID (WIA.CommonDialog)

末鹿安然 提交于 2019-12-04 04:43:47

问题


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.


回答1:


The MSDN reference states that to enable COM Interop inside the browser, you must

  1. Set Registry Key HKEY_LOCAL_MACHINE\Software\Microsoft\Silverlight\ (or on x64 HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Silverlight\) AllowElevatedTrustAppsInBrowser DWORD 0x0000001

  2. Check your group policy has not disabled AllowInstallOfElevatedTrustApps and AllowLaunchOfElevatedTrustApps

  3. Sign the .xap

  4. Install cert to Trusted Application Store (see screenshots illustrating how)

Additionally, you must

  1. configure as Out of Browser Application (even if you are not running Out of Browser)

  2. before calling the ComAutomationFactory.CreateObject you should check for Application.Current.HasElevatedPermissions and AutomationFactory.IsAvailable

  3. 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

  1. Use ProcMon to verify that the AllowElevatedTrustAppsInBrowser registry key is being read

  2. Attach Debugger to Silverlight (see screenshots)

  3. MSIE Protected Mode settings can also adversely affect whether a Silverlight application can run with Elevated Permissions. Try running with different Protected Mode settings.



来源:https://stackoverflow.com/questions/30642662/failed-to-create-an-object-instance-for-the-specified-progid-wia-commondialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!