Forum Xamarin Xamarin.Forms

Windows Phone 8.1 Navigation.PushAsync(new page()); Crash!!!!

Dear All, I got a Xamarin.Forms app that I've compiled and starts both on the emulator and phone (WP 8.1) then after a few calls from different pages to Navigation.PushAsync(new Page()); the app closes without a exception or anything. Any ideas?

The same app runs without problems on Android and Windows 8.1

Posts

  • Forgot to mention Xamarin version 2.0.1

  • PranavSharmaPranavSharma AUMember

    On windows phone when trying to navigate to a tabbed page my app is crashing as well strangely the code works fine on iOS and Android
    I get this error
    Error: {"Object reference not set to an instance of an object."}

    Xamarin.Forms 2.1.0.6501-pre1

  • JohnHardmanJohnHardman GBUniversity admin
    edited January 2016

    @PranavSharma - When you say Windows Phone, do you mean 8.1 WinRT or 8.0 Silverlight?

    @GermanOlivares @PranavSharma - If you are running in a debug session, unhandled exceptions will be available in the debugger as a result of the following code:

            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
            };
    

    which occurs in the following block.

        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public void InitializeComponent()
        {
            if (_contentLoaded)
                return;
    
            _contentLoaded = true;
    #if DEBUG && !DISABLE_XAML_GENERATED_BINDING_DEBUG_OUTPUT
            DebugSettings.BindingFailed += (sender, args) =>
            {
                global::System.Diagnostics.Debug.WriteLine(args.Message);
            };
    #endif
    #if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
            UnhandledException += (sender, e) =>
            {
                if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
            };
    #endif
        }
    

    You should be able to find out where unhandled exceptions are occurring by looking at the exception detail in the debugger.

    I would suggest also checking for exceptions in your own code, where you do the calls to Navigation.PushAsync . IMHO, it's worth creating a small helper function so that you only have one place where PushAsync is called.

    It is also worth adding support for Xamarin.Insights (or an equivalent product). This will report back to you details of any unhandled exceptions that occur.

  • Hi,
    It is windows phone 8.1 (Silverlight, I believe normally the project details in the solution explorer says Silverlight in the title but I don't see it).

    I put a break point at:

    UnhandledException += (sender, e) =>
    {
    if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
    };
    but it never hits, I have seen this exception get thrown in other parts of the application when something is not working right but nothing like this.

    I also tried just doing the Navigation.PushAsync(new Page()); in a single page, and just calling a new page, doing a pop to close the page and then doing a push again. The problem still persists, sometimes after the 1st push, sometimes after a couple pushes. I did notice that if you run the app directly from the emulator without doing a compile it takes a couple more pushes?

    Thanks,

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @JohnHardman - sometimes Windows debugging doesn't quite cut it :) Especially if a crazy XF bug or an OutOfMemory exception.

    @PranavSharma - You don't happen to have a Toolbar on your TabbedPage do you? If so I posted this bug a little while ago: https://bugzilla.xamarin.com/show_bug.cgi?id=37601 which might be it. This is on WP81SL but could also exist in RT.

    @GermanOlivares - Can you run the Windows Phone Profiler and see what your memory usage is. After a few pushes and a strange crash, it sounds like an OutOfMemory exception but it would be good to at least rule that out.

  • Chris.CooperChris.Cooper USMember
    edited January 2016

    I have the same issue as PranavSharma, pushing a new TabbedPage crashes with "Object reference not set to an instance of an object.", and the exception contains no stack trace.
    Its a wp silverlight 8.1 project. The iOS and Android versions work fine.

    Edit: That bug looks like my problem. Didn't read it at first because I didn't have a toolbar on my tabbed page, the bug is actually with having a toolbar on the page being navigated from.

  • JohnHardmanJohnHardman GBUniversity admin

    @AdamP - I don't think I've ever had an out-of-memory situation in C#, so I just intentionally put one in my code to see how it was handled and tested the handling on my WinPhone 8.1 build.

    I started by putting it in the constructor of a page view. That just created a System.OutOfMemoryException that my existing exception handling caught, reported to the user (currently only does that in a debug build). and reported via Xamarin.Insights as expected.

    I then moved it to my OnAppearing override, which is already wrapped in a try/catch (as is any code that is called from XF, whether via overrides, events etc). Again a System.OutOfMemoryException was caught and handled as above.

    I then moved it to an OnSizeAllocated override, again already wrapped in a try/catch block. This was more interesting. My exception handling caught it and reported it as above. However, the dialog used in debug builds to report to the user threw another exception, as follows:
    Message "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" string
    StackTrace " at Windows.UI.Popups.MessageDialog.ShowAsync()\r\n at Xamarin.Forms.Platform.WinRT.Platform.d__52.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__3(Object state)\r\n at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()" string

    This was unhandled, so ended up hitting the Break in the code I posted previously, which is what would be expected.

    A bit of investigation showed that the exception handling was getting recursive if an error occurred when showing the MessageDialog, so I added a recursion check. Problem solved - the out of memory reported successfully via the dialog box and via Xamarin.Insights. The application then allowed me to continue using it. Doing a back from the page where I forced the out of memory allowed the memory to be collected and everything carried on as expected.

    Whilst not a comprehensive test of what happens when out of memory occurs, I reckon those are the most likely places. I cannot see any reason that an app would throw an exception that cannot be caught with appropriate handling. Inevitably, people debate whether out of memory should be caught, but IMHO if memory can be collected by backing out of a page, I'd say catching an out of memory for a page and isolating it there is not unreasonable - I'd rather warn the user and have one page inaccessible until the user decides to restart the app, rather than have the app fail completely.

    An interesting exercise that found one slightly flaky piece of code in a debug build that has now been improved :-)

  • JohnHardmanJohnHardman GBUniversity admin

    @GermanOlivares - Can you post the small piece of code that shows this failing pls.

    Are you using await everywhere you should? Are there any warnings (on W4) produced when you build the code?

  • PranavSharmaPranavSharma AUMember

    @JohnHardman It's a Windows Phone 8.0
    @AdamP No toolbar on tabbed page

    I tried few different things and it turns out if i roll back to Xamarin.Forms 1.5.1.6471 it works just fine. I have been facing issues with custom renderer as well which i use to display AdMob ads. Ads get displayed with 1.5.1.6471 but not with latest stable package. Not facing any such issues on iOS or Android it's just windows phone 8.0 issues.

    I'll upload a small solution with both packages

  • Paul_RoyPaul_Roy FRMember ✭✭
    edited January 2016

    I am experiencing this bug a lot too. My project is a Windows Phone Silverlight 8.1 and warning are considered as errors which means I am sure I have no code warning.

    It happens with a TabbedPage but also with a view having a few grids. Like the other I have the Unhandled exception with Error: {"Object reference not set to an instance of an object."}. No stacktrace to debug nor any indication on where to begin.

    I rolled back too, again. It is just a complete no go for an update.
    When I tried XF 2.0 I had the issue and rollbacked and now with 2.1 I still have the issue. No problem on Android or iOS. I am 100% sure this comes from the framework and not from our code.

    I always feel like WP is left alone with Xamarin Forms :-/

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @Paul_Roy - I agree with you on the WP not getting as much attention, however Xamarin seem to disagree with me and anyone else who mentions it on that aspect.

    @JohnHardman - OutOfMemory exceptions are normally captured however I came across one a while ago (I can't even remember the exact repro steps) but I loaded the camera (so the app gets backgrounded), then I come back in and it OME's within loading back up again I had the app just close, no exceptions caught.

  • Paul_RoyPaul_Roy FRMember ✭✭

    I was able to pull up a stacktrace!

        Xamarin.Forms.Platform.WP8.DLL!Xamarin.Forms.Platform.WinPhone.ImageRenderer.GetDesiredSize(double widthConstraint, double heightConstraint)    Unknown
        Xamarin.Forms.Platform.WP8.DLL!Xamarin.Forms.Platform.WinPhone.Platform.Xamarin.Forms.IPlatform.GetNativeSize(Xamarin.Forms.VisualElement view, double widthConstraint, double heightConstraint)    Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.VisualElement.OnSizeRequest(double widthConstraint, double heightConstraint)   Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Image.OnSizeRequest(double widthConstraint, double heightConstraint)   Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.VisualElement.GetSizeRequest(double widthConstraint, double heightConstraint)  Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Grid.CalculateAutoCells(double width, double height)   Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Grid.Measure(double width, double height, bool requestSize)    Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Grid.OnSizeRequest(double widthConstraint, double heightConstraint)    Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.VisualElement.GetSizeRequest(double widthConstraint, double heightConstraint)  Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Layout.GetSizeRequest(double widthConstraint, double heightConstraint) Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Grid.CalculateAutoCells(double width, double height)   Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Grid.Measure(double width, double height, bool requestSize)    Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Grid.LayoutChildren(double x, double y, double width, double height)   Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Layout.UpdateChildrenLayout()  Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Layout.OnSizeAllocated(double width, double height)    Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Layout.OnChildMeasureInvalidated(Xamarin.Forms.VisualElement child, Xamarin.Forms.InvalidationTrigger trigger) Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.Layout.OnChildMeasureInvalidated(object sender, System.EventArgs e)    Unknown
        Xamarin.Forms.Core.DLL!Xamarin.Forms.VisualElement.InvalidateMeasure(Xamarin.Forms.InvalidationTrigger trigger) Unknown
        Xamarin.Forms.Platform.WP8.DLL!Xamarin.Forms.Platform.WinPhone.VisualElementRenderer<Xamarin.Forms.Button, System.Windows.Controls.Button>.MeasureOverride(System.Windows.Size availableSize)   Unknown
        System.Windows.ni.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, out double outWidth, out double outHeight)   Unknown
        [Native to Managed Transition]  
        [Managed to Native Transition]  
        System.Windows.ni.dll!MS.Internal.XcpImports.UIElement_Measure(System.Windows.UIElement element, System.Windows.Size availableSize) Unknown
        System.Windows.ni.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)   Unknown
        Xamarin.Forms.Platform.WP8.DLL!Xamarin.Forms.Platform.WinPhone.VisualElementRenderer<Xamarin.Forms.View, System.Windows.FrameworkElement>.MeasureOverride(System.Windows.Size availableSize)    Unknown
        System.Windows.ni.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, out double outWidth, out double outHeight)   Unknown
        [Native to Managed Transition]  
        [Managed to Native Transition]  
        System.Windows.ni.dll!MS.Internal.XcpImports.UIElement_Measure(System.Windows.UIElement element, System.Windows.Size availableSize) Unknown
        System.Windows.ni.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)   Unknown
        Xamarin.Forms.Platform.WP8.DLL!Xamarin.Forms.Platform.WinPhone.VisualElementRenderer<Xamarin.Forms.Page, System.Windows.Controls.Panel>.MeasureOverride(System.Windows.Size availableSize)  Unknown
        System.Windows.ni.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, out double outWidth, out double outHeight)   Unknown
        [Native to Managed Transition]  
        [Managed to Native Transition]  
        System.Windows.ni.dll!MS.Internal.XcpImports.UIElement_Measure(System.Windows.UIElement element, System.Windows.Size availableSize) Unknown
        System.Windows.ni.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)   Unknown
        Xamarin.Forms.Platform.WP8.DLL!Xamarin.Forms.Platform.WinPhone.VisualElementRenderer<Xamarin.Forms.NavigationPage, System.Windows.FrameworkElement>.MeasureOverride(System.Windows.Size availableSize)  Unknown
        System.Windows.ni.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, out double outWidth, out double outHeight)   Unknown
    
    
  • JohnHardmanJohnHardman GBUniversity admin

    @PaulRoy - If that's the location that you get the null reference exception, I'd recommend raising a bug in bugzilla.

    Xamarin have recently taken a look at some of the WinPhone related bugs I have reported, but I echo your and Adam's sentiments. The whole bug-fixing process seems incredibly slow, but particularly so for Windows platforms. I reckon that Xamarin should add a role to their list of open vacancies to get somebody on board to really focus on this area.

  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    @PaulRoy I have looked into this code, its a very odd place to be getting an NRE, I have no idea how its happening to be honest. Control must somehow be null but that shouldn't really ever be the case, either way I am adding the null check.

  • TheRealJasonSmithTheRealJasonSmith USXamarin Team Xamurai

    @AdamP Windows Phone is a tricky beast, of all the platforms it is easily the one with the strangest behaviors and bugs. Buttons that get different size measurements when asked twice in a row, ListViews that cant handle all INCC events, ListViews that disable virtualization if cells are a different size... sometimes... I mean man I could go on for hours of the crazy shit we found and have had confirmed upstream. Often times simple looking issues are not.

    The issues are often made worse because in any particular instance a fix might be simple as a workaround, but generalizing that fix to anything you can do with Forms is a lot harder.

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @TheRealJasonSmith - Not to mention MS rewrote the platform 3 times (SL, RT, UWP) :)

    I certainly understand that they are crazy issues, most of my bug filings are insane, such as my memory leak at 22+ listview items, or pages mysteriously entering the modal stack, all on Windows only though.

    I unfortunately have to put significant allocations in project budgets now for accounting for these types of errors. I haven't had one project that was bug free. I still think XF provides more value for time and overall a quicker project than if developing for 3 platforms separately, it just puts a bit of a dampener on how insanely fast we could get things done otherwise.

  • Paul_RoyPaul_Roy FRMember ✭✭

    @TheRealJasonSmith Thanks :)
    If we could have a reproduction project it would be best to know why this happens (I confess, I have decompiled the code and that is indeed a weird place to get a NRE) but having this check is already nice.

    I understand WP is a tricky platform.

  • SedativeSedative SIMember

    I Had the same problem (when navigating with Navigate.PushAsync() application closed), and been pulling my hair out for this one.

    But i think i finally figure it out.

    for win phone, you have to explicitly call the dispacher on the main UI thread to navigate:

    Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>Navigation.PushAsync(new Page()));

    Hope this helps.

    Regards.

Sign In or Register to comment.