How do you trace exception info in browser forms with managed code? - InfoPath Dev
in

InfoPath Dev

How do you trace exception info in browser forms with managed code?

Last post 12-22-2009 02:03 AM by Karsten Brocksieper. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-18-2009 05:50 AM

    How do you trace exception info in browser forms with managed code?

    Hi,

    Can you share your experience on what you can do to get more information about Exceptions?

    I mean those logged in ULS like

    12/18/2009 16:26:51.95  w3wp.exe (0x1358)                        0x1244 Forms Server                   Forms Services Runtime - Busine 82g6 Warning  Business logic failed due to an exception. (User: DOMAIN\UserName, Form Name: MyForm, IP: , Request: http://portalserver:9999/_layouts/Postback.FormServer.aspx, Form ID: urn:schemas-microsoft-com:office:infopath:trySZ:-myXSD-2009-12-16T08-31-29, Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object.) b6178426-454f-4d5b-b3f3-95acc35f8dd3

    Is there any code snippet you can share for logging detailed information on what was happening and what the exception source is?

    Thanks in advance.

  • 12-21-2009 02:19 PM In reply to

    Re: How do you trace exception info in browser forms with managed code?

    For better understanding of the question: the NullReferenceException appears in a form designed as browser-enabled and perfectly fuctional when filled in InfoPath (not in the browser). My suspicion is that I might have lost some state info during a postback...

  • 12-21-2009 02:20 PM In reply to

    Re: How do you trace exception info in browser forms with managed code?

    Hello,

    I´m not sure if this is what you are looking for ...

    For logging and tracing purpose I always use the (free) product "log4Net" (http://logging.apache.org/log4net/index.html). You have to build your own wrapper class for log4net. It´s important that this class is serializable because you have to initialize this class in a FormState object like in the following code example:

    private Log4Net log4Net{
      get {return (Log4Net)FormState["log4Net"];}
      set {FormState["log4Net"] = value;}
    }

    ... and in the "FormEvents_Loading"

    FormState.Add("log4Net",new Log4Net());

    The you can trace your programm with the following code lines:

    this.log4Net.Debug("This is my first tracing entry ...");

    or in case of an exception:

    this.log4Net.Error("FormEvents_Loading failed.", ex);

    As a result you get a file with detailed tracing information like in the following sample... 

    21.12.2009 17:39:33,224 [12   ] INFO   Form ----------------------------------
    21.12.2009 17:39:33,255 [12   ] INFO   Form New instance of class Log4Net created.
    21.12.2009 17:39:33,286 [12   ] INFO   Form >>>> FormCode.FormEvents_Loading
    21.12.2009 17:39:33,286 [12   ] DEBUG  Form    Start FormEvents_loading ...
    21.12.2009 17:39:33,286 [12   ] DEBUG  Form    This is my first tracing entry...
    21.12.2009 17:39:33,286 [12   ] DEBUG  Form    Get current WebSite:
    http://moss/sites/test
    21.12.2009 17:39:33,302 [12   ] INFO   Form    >>>> FormCode.CheckGroupMembership
    21.12.2009 17:39:33,395 [12   ] DEBUG  Form       Check if current user is Administrator: True
    21.12.2009 17:39:33,395 [12   ] INFO   Form    <<<< FormCode.CheckGroupMembership (93.7806 ms)
    21.12.2009 17:39:33,395 [12   ] INFO   Form    >>>> FormCode.GetSPUser
    21.12.2009 17:39:33,395 [12   ] DEBUG  Form       Currently logged in user login: domain\administrator
    21.12.2009 17:39:33,395 [12   ] INFO   Form    <<<< FormCode.GetSPUser (< 1 ms)
    21.12.2009 17:39:33,395 [12   ] DEBUG  Form    Set currentFormUser (hidden field): domain\administrator
    21.12.2009 17:39:33,395 [12   ] INFO   Form    >>>> FormCode.GetSPUser
    21.12.2009 17:39:33,395 [12   ] DEBUG  Form       Currently logged in user login: domain\administrator
    ...
    and so on...

    Please ask me if you need further information...

    Regards,


     

     

    Karsten
    Filed under:
  • 12-21-2009 02:45 PM In reply to

    Re: How do you trace exception info in browser forms with managed code?

    Nice output. Thanks, I'll take a look at log4net for tracing. As for live debugging: Can someone hint at how to force catching Forms Services Exceptions in Visual Studio Debugger?
  • 12-22-2009 02:03 AM In reply to

    Re: How do you trace exception info in browser forms with managed code?

    Hi,

    debugging InfoPath forms that are opened in the browser requires the following steps:

    1) Ensure the InfoPath Form Template is compiled in the Debug Configuration so the XSN includes the symbol (PDB) file
    2) Open the local copy of the code file in Visual Studio and set a breakpoint
    3) Attach to the appropriate w3wp process
    4) Execute the process that will cause the breakpoint to be hit

    You can find detailed information here:

    http://blogs.msdn.com/infopath/archive/2006/11/24/debugging-browser-forms.aspx

    Regards,

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