Hi again.
I've written code to populate a form errors list (to be displayed in an errors view when users trigger a button). It works great in client view, but fails in a browser-enabled form. After having spent a considerable time trying to solve this, I've concluded I'm in need of your considerable expertise.
Tests indicate that the FormError properties (e.g. Message, Site.LocalName etc) are causing the problem.
Here is the error message:
Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at devIMDI_Soknad_P71Info2010.FormCode.ViewErrors_Clicked(Object sender, ClickedEventArgs e)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.<>c__DisplayClass6.<>c__DisplayClassa.<add_Clicked>b__3()
at Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.<>c__DisplayClass6.<add_Clicked>b__2(Object sender, ClickedEventArgs e)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.FireClickedEvent(Object sender, ClickedEventArgs args)
at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonFormCode.<>c__DisplayClass2.<>c__DisplayClass5.<Click>b__1()
at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandling(UserMessages userMessages, OMCall d)
An entry has been added to the Windows event log of the server.
Log ID:5337
And here are excerpts of the code that triggers the error:
public void ViewErrors_Clicked(object sender, ClickedEventArgs e)
{
DataSource ErrorsList = this.DataSources["ErrorsList1"];
XPathNavigator root = ErrorsList.CreateNavigator();
root.MoveToFirstChild();
NameTable nTbl = new NameTable();
XmlNamespaceManager nsMgrErrors = new XmlNamespaceManager(nTbl);
nsMgrErrors.AddNamespace("nsErr", root.NamespaceURI.ToString());
string ErrorsGroup = "/nsErr:myFields/nsErr:ErrorsTable";
int errCount = 0; //Setting counter to 0
FormError[] myErrors;
myErrors = this.Errors.GetErrors(FormErrorType.SchemaValidation);
XPathNavigator CurGroup = ErrorsList.CreateNavigator().SelectSingleNode(ErrorsGroup, nsMgrErrors);
foreach (FormError err in myErrors)
{
//ADDS NEW GROUP ELEMENT
XPathNavigator NewGroup = CurGroup.Clone();
NewGroup.InsertAfter(CurGroup);
errCount = errCount + 1;
//WRITES ERRORDATA TO NEW ERRORNODE
NewGroup.SelectSingleNode("nsErr:NrErr", nsMgrErrors).SetValue(errCount.ToString());
NewGroup.SelectSingleNode("nsErr:ErrMessage", nsMgrErrors).SetValue(err.Message.ToString());
NewGroup.SelectSingleNode("nsErr:ErrSiteLocalName", nsMgrErrors).SetValue(err.Site.LocalName.ToString());
}
}
Other info: Full trust form. Signed with a certificate I've generated myself (it has worked before). Cross-Domain Access for User Form Templates is enabled on the server (in case that should be the issue).
Would you be so kind to assist me?