string.Split(char)[int] in browser causes System.IndexOutOfRangeException: Index was outside the bounds of the array. - InfoPath Dev
in

InfoPath Dev

string.Split(char)[int] in browser causes System.IndexOutOfRangeException: Index was outside the bounds of the array.

Last post 12-18-2009 02:00 AM by ACrush. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 12-18-2009 12:56 AM

    string.Split(char)[int] in browser causes System.IndexOutOfRangeException: Index was outside the bounds of the array.

    I have a browser-enabled form that works in InfoPath and fails with System.IndexOutOfRangeException: Index was outside the bounds of the array.
    \FormCode.cs:line 36 
    at Microsoft.Office.InfoPath.Server.SolutionLifetime.XmlEventExternal.<>c__DisplayClass10.<>c__DisplayClass12.b__b()
    at Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk)
    at Microsoft.Office.InfoPath.Server.SolutionLifetime.XmlEventExternal.<>c__DisplayClass10.b__a(Object sender, XmlEventArgs e)
    at Microsoft.Office.InfoPath.Server.SolutionLifetime.XmlEventExternal.<>c__DisplayClass20.b__1c()
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandling(UserMessages userMessages, OMCall d)

    The line 36 containing CreateNavigator() was indicated in the exception message in the browser. Why? Is there any discrepancy between line numbering in the source code/dll?

    I think the error might arise from the line with if(...Split()[1]) but the indication is misleading. Any ideas?

    the code goes like this:
    public void Recepients_Changed(object sender, XmlEventArgs e)
    {
    XPathNavigator n = this.CreateNavigator(); //same as this.MainDataSource.CreateNavigator();

    switch (e.Operation)
    {
    case XmlOperation.Delete:
    case XmlOperation.ValueChange:
    case XmlOperation.Insert:
    n.SelectSingleNode("/my:FormRoot/my:RecepientsCount", NamespaceManager)
    .SetValue(string.Empty);
    n.SelectSingleNode("/my:FormRoot/my:RecepientsList", NamespaceManager)
    .SetValue(string.Empty);
    n.SelectSingleNode("/my:FormRoot/my:RecepientsCount", NamespaceManager)
    .SetValue(
    n.Select("/my:FormRoot/my:Recepients/my:Person", NamespaceManager)
    .Count.ToString()
    );
    XPathNodeIterator i = n.Select("/my:FormRoot/my:Recepients/my:Person", NamespaceManager);
    while (i.MoveNext())
    {
    if (
    DataSources["Recepients"].CreateNavigator()
    .SelectSingleNode("//dfs:Recepients[@Person='"+
    i.Current.SelectSingleNode("my:AccountId",NamespaceManager)
    .Value.Split(@"\".ToCharArray()[0])[1]
    +"']", NamespaceManager) != null
    )
    {

    n.SelectSingleNode("/my:FormRoot/my:RecepientsList", NamespaceManager)
    .SetValue(
    (n.SelectSingleNode("/my:FormRoot/my:Recepients/my:Person/my:AccountType", NamespaceManager)
    .Value=="User")
    ? n.SelectSingleNode("/my:FormRoot/my:RecepientsList", NamespaceManager).Value + i.Current
    .SelectSingleNode("my:DisplayName", NamespaceManager)
    .Value+"; "
    : string.Empty
    );
    }
    }
    break;
    default: break;
    }

    }


    thanks in advance
  • 12-18-2009 01:50 AM In reply to

    Re: XPathNavigator = this.CreateNavigator(); //-> System.IndexOutOfRangeException: Index was outside the bounds of the array.

    I have found that the culprit is in the string.Split(char) method. The exception is thrown (but doesn't cancel the actual splitting) if you uncomment the Split part in the following simple sequence:

    string login = i.Current.SelectSingleNode("my:AccountId", NamespaceManager).Value/*.Split('\\')[1]*/;
    n.SelectSingleNode("/my:FormRoot/my:RecepientsList", NamespaceManager).SetValue(login);
  • 12-18-2009 02:00 AM In reply to

    Re: XPathNavigator = this.CreateNavigator(); //-> System.IndexOutOfRangeException: Index was outside the bounds of the array.

    This works:

    string login = i.Current.SelectSingleNode("my:AccountId", NamespaceManager)
    .Value
    /*.Split('\\')[1]*/;
    login = login.Substring(login.IndexOf(
    '\\')+1);
    n.SelectSingleNode(
    "/my:FormRoot/my:RecepientsList", NamespaceManager).SetValue( login );
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.