1

I know it's crazy but I'm facing an unexpected and really triggering issue. When started, my application (vb.net desktop app in .net 4.7 fmk) reads an xml file containing some local settings for the app. Now, the issue is that if I login into windows as administrator everything is fine. If I access as a normal user, the file itself is not read properly. The app gives me this error

System.IndexOutOfRangeException(0x80131508): No row at position 12. in System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) in System.Data.DataRowCollection.get_Item(Int32 index) in Health.NET.FrmLogin.OnLoad(EventArgs e)

In the XML row 12 actually exists. The xml file is the same despite the user that log in windows. Two even more weird effects: 1- that the error comes at row 12, but some of the previous rows are read returning zero values even if the xml has no zero values for that setting. 2- this error occurs only on one client in an environment of 30 clients.

Basically it's the first time this happens in 7 years of application's honored service.

Does anybody has any clue to solve this craziness??

Here's some raw code I'm using. It's pretty standard code

            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

So far everything is read correct, and the same for few lines ahead But when coming to this:

            ' 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
  • THESE ARE READ BUT WITH 0 value instead of a given non zero value

              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
    
  • THE 3 previous lines ARE READ correct

              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
    
  • Try to read row 12 throws the error, even if it is actually in the XML

I stand it again: as administrator logged in, everything is fine

Please HELP

EDIT: If logged with a regular user but start the app with admin privilege everything works fine :-O The folder containing the xml has full control for 'Everyone' set

Efrael
  • 557
  • 1
  • 4
  • 11

1 Answers1

0

JUST A CLUE TOO LONG FOR A COMMENT: The problem might be that Application.StartupPath is different for each user using app deployed using ClickOnce. I just assume that it is and that one particular user doesn't have valid xml content in that location.

According to the documentation.

This path will be different depending on whether the Windows Forms application is deployed using ClickOnce. ClickOnce applications are stored in a per-user application cache in the C:\Documents and Settings\username directory.

The question is how it is actually deployed and if you have the power to check that environment to validate the file is there in a state it should be.

Let me know if it might be it. If not, I will remove the answer. Thanks

dropoutcoder
  • 2,627
  • 2
  • 14
  • 32
  • Thanks for the answer. The app is deployed with a common windows installer. By the way I logged the 'Path' variable and it returns the same path for both admin and non admin users. Even more: I logged the number of rows in the dataset after the xml is read and when logged as administrator it returns 14 rows as administrator and 12 rows as regular user – Efrael Mar 09 '21 at 23:43
  • 1
    Okay. That is really weird. Only thing I can now think of to find the problem is to check `if(ds.HasErrors) { var errors = ds.Tables.Item(0).GetErrors(); // log it }`. [Example in docs](https://learn.microsoft.com/en-us/dotnet/api/system.data.datatable.geterrors?view=netframework-4.7#examples) – dropoutcoder Mar 10 '21 at 00:33
  • Thank you, this could be helpful. I will try and let you know – Efrael Mar 10 '21 at 17:15