问题描述
我知道这很疯狂,但我正面临一个意想不到且真正触发的问题。 启动时,我的应用程序(.net 4.7 fmk 中的 vb.net 桌面应用程序)读取一个 xml 文件,其中包含该应用程序的一些本地设置。 现在,问题是如果我以管理员身份登录 Windows,一切都很好。如果我以普通用户身份访问,则无法正确读取文件本身。该应用程序给了我这个错误
system.indexOutOfRangeException(0x80131508):位置 12 没有行。 在 System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) 在 System.Data.DaTarowCollection.get_Item(Int32 索引) 在 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 的文件夹具有对“所有人”集的完全控制
解决方法
评论太长了:问题可能是每个用户使用 ClickOnce 部署的应用程序的 Application.StartupPath 是不同的。我只是假设是这样,并且某个特定用户在该位置没有有效的 xml 内容。
此路径将根据 Windows Forms 是否 应用程序是使用 ClickOnce 部署的。 ClickOnce 应用程序是 存储在 C:\Documents 和 设置\用户名目录。
问题在于它是如何实际部署的,以及您是否有权检查该环境以验证文件是否处于应有的状态。
如果是这样,请告诉我。如果没有,我将删除答案。谢谢