This is a migrated thread and some comments may be shown as answers.

Unhandeled exeption of type "System.NullReferenceException" at monitor.Stop() event

3 Answers 54 Views
Monitor integration
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dino
Top achievements
Rank 1
Dino asked on 31 Aug 2013, 01:29 PM
i get this error during the monitor:stop(); event at the application closing, i use the back key press to call this event this is the code i used

public partial class MainPage : PhoneApplicationPage
    {
        private IAnalyticsMonitor monitor;  

 private void PhoneApplicationPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            IAnalyticsMonitor monitor = AnalyticsMonitorFactory.CreateMonitor("9A603DCBB60C4F02B30DCAB99AC9D415");

monitor.Start();
          
        }

and further down in my code i have this event 


        private void Window_Closed(object sender, CancelEventArgs e)
        {
          monitor.Stop();
        }

now on the application closing i get this error of "unhandled exception of type "System.NullReferenceException", what am i doing wrong?! and how can this be fixed or handled?

3 Answers, 1 is accepted

Sort by
0
Soren
Telerik team
answered on 01 Sep 2013, 02:12 PM
Hello Dino,

Sorry for your troubles. Let me see if I can help you out. Can you start by confirming that the unhandled exception is not caused by the monitor instance being null within your own code? I'm not terribly familiar with the page lifecycle for Phone applications but if the Loaded event is somehow not fired then the Close event will try to reference a null variable. Perhaps you should guard the code in your Close event handler with a null-check and see if that fixes the issue?

If it does not fix the issue, I'd appreciate a as much of a stacktrace (including inner exceptions) as possible in order to determine where the error may originate.

Looking forward to hearing from you.
 
Regards,
Soren
Telerik
JAVASCRIPT MONITOR (BETA) AVAILABLE FOR DOWNLOAD.
Monitor web applications with the new EQATEC Application Analytics JS library. Compatible with all modern browsers.
Test it today >>
0
Dino
Top achievements
Rank 1
answered on 03 Sep 2013, 03:16 PM
My code is ok if i remove the analytics, and i can start monitor.Start(); directly after the call

 IAnalyticsMonitor monitor = AnalyticsMonitorFactory.CreateMonitor( my key );

but i can not stop it on the same page with lets say the backbutton exit from the app, or with any other behaviour or method. the problem is i can call monitor.stop(); only in this one method. and if i make an reference on this page to monitor its give me this error above. so the problem is i cant make an reference to use it in the code under this class
0
Soren
Telerik team
answered on 06 Sep 2013, 09:03 AM
Hello Dino,

I think you should look into how you manage the IAnalyticsMonitor instance in your code. Ideally, you should only create and start the instance once for your entire application, which should typically be done in a Main method, a Bootstrapper etc.. Dependent upon your specific architecture, you could e.g. store the created instance in a static variable or somewhere similar.

The key issue is that the monitor should be created once in your application and all your tracking code should reference this instance. From looking at your sample codes, your issues seems to originate from the fact the your IAnalyticsMonitor instance is not reachable when you need to call start.

Hope this helps

Regards,
Soren
Telerik
JAVASCRIPT MONITOR (BETA) AVAILABLE FOR DOWNLOAD.
Monitor web applications with the new EQATEC Application Analytics JS library. Compatible with all modern browsers.
Test it today >>
Tags
Monitor integration
Asked by
Dino
Top achievements
Rank 1
Answers by
Soren
Telerik team
Dino
Top achievements
Rank 1
Share this question
or