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