1

我知道这很疯狂,但我正面临一个意想不到且真正触发的问题。启动时,我的应用程序(.net 4.7 fmk 中的 vb.net 桌面应用程序)读取一个 xml 文件,其中包含应用程序的一些本地设置。现在,问题是如果我以管理员身份登录 Windows,一切都很好。如果我以普通用户身份访问,则文件本身无法正确读取。该应用程序给了我这个错误

System.IndexOutOfRangeException(0x80131508):在 System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) in System.Data.DataRowCollection.get_Item(Int32 index) 中的位置 12 处没有行 Health.NET.FrmLogin.OnLoad(EventArgs e )

在 XML 行中实际存在 12 行。尽管用户登录 Windows,但 xml 文件是相同的。两个更奇怪的效果:1-错误出现在第 12 行,但是即使 xml 没有该设置的零值,前面的一些行也被读取返回零值。2- 此错误仅发生在 30 个客户端的环境中的一个客户端上。

基本上这是应用程序的荣幸服务7年来第一次发生这种情况。

有没有人有任何线索来解决这个疯狂?

这是我正在使用的一些原始代码。这是非常标准的代码

            Dim ds As New DataSet
Dim Path as string = ""
            path = Application.StartupPath & "\LocalConfig.xml"
            ds.ReadXml(path)

            ' Set theme and LabelsPrinter
            If Not ds.Tables.Item(0).Rows(0).Item(0).ToString = String.Empty Then
                theme.Name = ds.Tables.Item(0).Rows(0).Item(0).ToString
            End If

            If Not ds.Tables.Item(0).Rows(2).Item(0).ToString = String.Empty Then
                LocalConfig.labelsPrinterName = ds.Tables.Item(0).Rows(2).Item(0).ToString
            End If

到目前为止,一切都是正确的,前面几行也是如此但是当谈到这一点时:

            ' Set LabelsSettings
            If Not ds.Tables.Item(0).Rows(7).Item(0).ToString = String.Empty Then
                LocalConfig.LabelMarginTop = ds.Tables.Item(0).Rows(7).Item(0)
            End If

            If Not ds.Tables.Item(0).Rows(8).Item(0).ToString = String.Empty Then
                LocalConfig.LabelMarginLeft = ds.Tables.Item(0).Rows(8).Item(0)
            End If
  • 这些被读取但带有 0 值而不是给定的非零值

              If Not ds.Tables.Item(0).Rows(9).Item(0).ToString = String.Empty Then
                  LocalConfig.UseLabelSettings = ds.Tables.Item(0).Rows(9).Item(0)
              End If
    
              ' Set Other Settings
              If Not ds.Tables.Item(0).Rows(10).Item(0).ToString = String.Empty Then
                  LocalConfig.DefaultZoomMinutes = ds.Tables.Item(0).Rows(10).Item(0)
              End If
    
              If Not ds.Tables.Item(0).Rows(11).Item(0).ToString = String.Empty Then
                  LocalConfig.DefaultKeepActualPlanningOnAddNew = ds.Tables.Item(0).Rows(11).Item(0)
              End If
    
  • 前 3 行是正确的

              If Not ds.Tables.Item(0).Rows(12).Item(0).ToString = String.Empty Then
                  LocalConfig.LabelPaperSizeX = ds.Tables.Item(0).Rows(12).Item(0)
              End If
              If Not ds.Tables.Item(0).Rows(13).Item(0).ToString = String.Empty Then
                  LocalConfig.LabelPaperSizeY = ds.Tables.Item(0).Rows(13).Item(0)
              End If
    
  • 尝试读取第 12 行会引发错误,即使它实际上在 XML 中

我再次忍受:作为管理员登录,一切都很好

请帮忙

编辑:如果使用普通用户登录,但以管理员权限启动应用程序,一切正常:-O 包含 xml 的文件夹对“所有人”集具有完全控制权

4

1 回答 1

0

评论太长了:问题可能是 Application.StartupPath 对于每个使用 ClickOnce 部署的应用程序的用户都不同。我只是假设它是并且某个特定用户在该位置没有有效的 xml 内容。

根据文档

根据是否使用 ClickOnce 部署 Windows 窗体应用程序,此路径会有所不同。ClickOnce 应用程序存储在 C:\Documents and Settings\username 目录中的每用户应用程序缓存中。

问题是它是如何实际部署的,以及您是否有权检查该环境以验证文件是否处于应有的状态。

让我知道它是否可能。如果没有,我将删除答案。谢谢

于 2021-03-09T23:36:33.607 回答