"方法失败,出现意外错误代码3"存储应用用户设置时

时间:2013-10-01 08:29:27

标签: .net vb.net internet-explorer add-in bho

我目前正在使用Internet Explorer BHO,它是使用Add-In Express(www.add-in-express.com).NET库在VB.NET中编写的,目标是.NET Framework 2.0。浏览器插件通过InnoSetup 5安装程序安装到用户的AppData / Local目录,该安装程序还处理插件的注册。

安装后,InnoSetup安装程序升级为UAC,可执行文件(由Add-In Express提供)将BHO注册到浏览器。

我必须指出,我的.NET体验至少是最小的 - 我知道足够的代码来编写应用程序,但实际上并不知道操作系统如何处理应用程序 - 我将尝试描述问题尽我所能。

我的附加组件使用的一个功能是Visual Studio的用户设置(通过VS中的属性 - >设置部分)。在原始开发机器上调试IE中的加载项时,一切都按预期工作。

将插件安装到新计算机时,只要我的应用程序尝试调用My.Settings.Save(),就会收到异常。我一直在努力在网上找到任何其他相同的场景来解决同样的问题。请在下面找到堆栈跟踪:

Exception Source:      mscorlib
Exception Type:        System.InvalidOperationException
Exception Message:     Method failed with unexpected error code 3.
Exception Target Site: CreateInternal

---- Stack Trace ----
   System.Security.AccessControl.NativeObjectSecurity.CreateInternal(resourceType As ResourceType, isContainer As Boolean, name As String, handle As SafeHandle, includeSections As AccessControlSections, createByName As Boolean, exceptionFromErrorCode As ExceptionFromErrorCode, exceptionContext As Object)
       mscorlib.dll: N 0306 (0x132) IL 
   System.Security.AccessControl.FileSystemSecurity..ctor(isContainer As Boolean, name As String, includeSections As AccessControlSections, isDirectory As Boolean)
       mscorlib.dll: N 0017 (0x11) IL 
   System.Security.AccessControl.FileSecurity..ctor(fileName As String, includeSections As AccessControlSections)
       mscorlib.dll: N 0000 (0x0) IL 
   System.Configuration.Internal.WriteFileContext.DuplicateTemplateAttributes(source As String, destination As String)
       mscorlib.dll: N 0008 (0x8) IL 
   System.Configuration.Internal.WriteFileContext.DuplicateFileAttributes(source As String, destination As String)
       mscorlib.dll: N 0028 (0x1C) IL 
   System.Configuration.Internal.WriteFileContext.Complete(filename As String, success As Boolean)
       mscorlib.dll: N 0018 (0x12) IL 
   System.Configuration.Internal.InternalConfigHost.StaticWriteCompleted(streamName As String, success As Boolean, writeContext As Object, assertPermissions As Boolean)
       mscorlib.dll: N 0070 (0x46) IL 
   System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.WriteCompleted(streamName As String, success As Boolean, writeContext As Object, assertPermissions As Boolean)
       mscorlib.dll: N 0000 (0x0) IL 
   System.Configuration.Internal.DelegatingConfigHost.WriteCompleted(streamName As String, success As Boolean, writeContext As Object, assertPermissions As Boolean)
       mscorlib.dll: N 0000 (0x0) IL 
   System.Configuration.ClientSettingsConfigurationHost.WriteCompleted(streamName As String, success As Boolean, writeContext As Object)
       mscorlib.dll: N 0019 (0x13) IL 
   System.Configuration.UpdateConfigHost.WriteCompleted(streamName As String, success As Boolean, writeContext As Object)
       mscorlib.dll: N 0036 (0x24) IL 
   System.Configuration.MgmtConfigurationRecord.SaveAs(filename As String, saveMode As ConfigurationSaveMode, forceUpdateAll As Boolean)
       mscorlib.dll: N 0793 (0x319) IL 
   System.Configuration.Configuration.SaveAsImpl(filename As String, saveMode As ConfigurationSaveMode, forceSaveAll As Boolean)
       mscorlib.dll: N 0036 (0x24) IL 
   System.Configuration.Configuration.Save()
       mscorlib.dll: N 0000 (0x0) IL 
   System.Configuration.ClientSettingsStore.WriteSettings(sectionName As String, isRoaming As Boolean, newSettings As IDictionary)
       mscorlib.dll: N 0219 (0xDB) IL 
   System.Configuration.LocalFileSettingsProvider.SetPropertyValues(context As SettingsContext, values As SettingsPropertyValueCollection)
       mscorlib.dll: N 0219 (0xDB) IL 
   System.Configuration.SettingsBase.SaveCore()
       mscorlib.dll: N 0154 (0x9A) IL 
   System.Configuration.SettingsBase.Save()
       mscorlib.dll: N 0016 (0x10) IL 
   System.Configuration.ApplicationSettingsBase.Save()
       mscorlib.dll: N 0023 (0x17) IL 
   FindAndRemind.User.DetectUser()
       mscorlib.dll: N 0042 (0x2A) IL 
   FindAndRemind.IEModule.IEModule_DownloadComplete()
       mscorlib.dll: N 0151 (0x97) IL 
   AddinExpress.IE.ADXIEModule.DoDownloadComplete()
       mscorlib.dll: N 0010 (0xA) IL

在搜索User / AppData目录后,我可以看到没有为组织名称创建文件夹。我还读到,user.config文件可以由Internet Explorer本身在Microsoft_Corporation文件夹下创建,尽管这也是空的。在我看来,这是一个权限问题,但由于我缺乏Windows编码应用程序的经验,我感到很茫然。

之前有没有人遇到过这个问题,如果有的话,你是怎么解决的?

提前致谢!

修改

我还应该指出异常可以关闭,应用程序可以继续运行,但是没有保存任何设置数据,这使我的插件本质上有点多余。

编辑2:

不幸的是,在管理员模式下运行Internet Explorer不是一种选择,因为加载项是对当前拥有20,000+用户群的旧版本的更新。我们的用户涵盖了一系列技能水平,并且插件应该在多个操作系统和用户设置中“按原样”工作。

2 个答案:

答案 0 :(得分:1)

确保已在安装包中包含加载项的配置文件。

此外,如果启用了Internet Explorer保护模式,则代码无法将任何内容保存到位于安装加载项的同一文件夹中的配置文件中。您可以实现自定义配置文件并将其复制到用户配置文件中的“Temporary Internet Files \ Low”文件夹。另一种解决方案是禁用保护模式。

答案 1 :(得分:0)

您是否尝试以管理员身份运行该应用程序?

  
    

当您右键单击某个应用程序并查看可用状态为“以管理员身份运行”的选项时,您可以查看该信息。