FormError properties fails in a browser-enabled form - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

FormError properties fails in a browser-enabled form

Last post 11-02-2010 05:28 PM by Hilary Stoupa. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 10-26-2010 09:31 AM

    FormError properties fails in a browser-enabled form

    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?

    Filed under:
  • 10-26-2010 12:32 PM In reply to

    Re: FormError properties fails in a browser-enabled form

    You need to find the line of code that is throwing the error -- not such an easy feat in a browser form. Theortically, you can use Visual Studio and attach to process for this -- in practice, I've never been successful with that approach.

    So, I do one of two things:

    1. Comment all the code out except the first line. Publish and open in the browser, click your button, make sure you don't have an error. Uncomment the next line. Repeat until you know what line is throwing the error so you can start figuring out why.
    2. Add a node for a message, and after each line, set the node's value ot text with the line number. Publish, open the form, click the button (make sure you have the node on whatever view you'll be seeing and the postback set on the control, and see what line you get to.

    You say you've narrowed the issue down to the Form Error properties -- Are you sure? Because your null reference exception could be occurring because the node you are trying to select from your NewGroup variable is null. You could split that out, check that the node (like NrErr) is not null prior to trying to set the value, just to be certain....

    Hilary Stoupa

  • 10-26-2010 11:31 PM In reply to

    Re: FormError properties fails in a browser-enabled form

    Hi Hilary,

    I already checked that NrErr works (and by the way, it's just a counter value that is set for each new repeating group). The error occurs when I uncomment the first FormError property (Message). I've also tried without writing error data to a new errornode (i.e. I've taken out NewGroup) and instead written an FormError property to a test variable:

    string TempVar = ""; 

    foreach (FormError err in myErrors)

                {

                 string TmpVar = err.Message.ToString());

                }

    And the code still throws the same error.

    Alf

  • 10-27-2010 04:45 PM In reply to

    Re: FormError properties fails in a browser-enabled form

    MSDN says the Message property is availble for both client and browser.... So, I'd expect it to HAVE a Message property. What about the Site property? Does it also return null?

    As a side note, there is an extra paren at the end of err.Message.ToString(), but I'm sure that's just a typo, 'cause you wouldn't be able to compile like that.... and since Message is a string, I think ToString() is redundant here...

    Hilary Stoupa

  • 11-01-2010 04:17 AM In reply to

    Re: FormError properties fails in a browser-enabled form

    Hi Hilary,

    Still throws the same error for Site property, e.g. Site.Localname.ToString(). (Here I believe ToString() is required. I've excluded other properties while testing).

    And yes, the extra parenthesis was a typo. I've also removed the superfluous ToString(), which didn't seem to influence the outcome anyway. 

    Without luck, I've already investigated the condition on MSDN that "This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions." Could my problem still have to do with that?

    Maybe I should also mention that I'm developing InfoPath 2007 browser-enabled forms using InfoPath Designer 2010 (with the compatibility mode set to IP 2007 browserform), and the forms are published to a SharePoint 2007 server. Soon we'll upgrade to SharePoint 2010, but I still have to survive with 2007 for some time.

    Any more ideas?

    Alf

  • 11-02-2010 05:28 PM In reply to

    Re: FormError properties fails in a browser-enabled form

    I just tried this with a sample form. Very simple form, with code that returns the error message to a field in the form. My form ran without issue -- no trouble with the code. I'm attaching it code and all in a zip to this post.

    The form was created in IP 2010, set to IP 2007 compatibility and admin deployed as a content type so it could be opened in the browser....

    Hilary Stoupa

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.