1

I am evaluating upgrading to MvvmCross v5.4 and I am getting an unhandled exception when calling Close on the MvxNavigationService. Unfortunately I am getting no further information on the exception.

I know if I add a handler for the BeforeClose or AfterClose events these get called, however after this, the exception occurs. It also occurs if I do not handle these events.

The view I am trying to close is an MvxDialogFragment. I am calling from within the MvxDiaglogFragments view model, so it is trying to close itself.

I am calling close as shown below

public IMvxAsyncCommand CancelCommand => new MvxAsyncCommand(async () =>
{
    try
    {
        await navigationService.Close(this);
    }
    catch (Exception ex)
    {
        logger.Error("An error occurred [{0}] [{1}]",
            ex.Message,
            ex.StackTrace);
    }
});

The catch does not catch the exception.

Any ideas?

Update this is the last line in the output window in Visual Studio 2017

11-14 17:09:13.526 D/Mono ( 8414): Assembly Ref addref MvvmCross.Binding[0xabc16b00] -> System.Reflection.Extensions[0xabc17dc0]: 5 An unhandled exception occured.

rideintothesun
  • 1,628
  • 2
  • 12
  • 29
  • Are you using `MvxDialogFragmentPresentationAttribute` on your `MvxDialogFragment`? Additionally, are you using `MvxAndroidViewPresenter` or `MvxAppCompatViewPresenter` and equivalent `MvxDialogFragment` from either the support library or native Android API? – Plac3Hold3r Nov 14 '17 at 17:34
  • FYI, there is an [open issue](https://github.com/MvvmCross/MvvmCross/issues/2378) with `IMvxNavigationService.Close` causing exceptions on Android while using `MvxAppCompatPresenter` and `MvxAppCompatDialogFragment`. This bug is triggered by rotating the device though. – Trevor Balcom Nov 14 '17 at 17:42
  • Yes, I am using MvxDialogFragmentPresentationAttribute on the MvxDialogFragment and I am using the MvxAppCompatViewPresenter. Should I be using MvxAppCompatDialogFragment instead of MvxDialogFragment? – rideintothesun Nov 14 '17 at 20:45
  • Unfortunately the same unhandled exception occurrs with a MvxCompatDialogFragment – rideintothesun Nov 15 '17 at 10:54
  • OK, managed to get a bit more information about the issue. I am getting System.NotSupportedException: Unable to activate instance of type from native handle. This makes me think that something is attempting to access the view after it has been disposed. – rideintothesun Nov 15 '17 at 11:49
  • 1
    I've managed to stop it happening by adding the following constructor. But this seems wrong to me, I don't think the view should be accessed once it is disposed. I'll raise an issue on this. protected MyDialogView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { } – rideintothesun Nov 15 '17 at 11:56
  • Bug https://github.com/MvvmCross/MvvmCross/issues/2389 – rideintothesun Nov 15 '17 at 13:34
  • This issue has been closed. I still think it is a bug as adding this constructor is hiding an issue. See the answer on this page for explanation https://stackoverflow.com/questions/10593022/monodroid-error-when-calling-constructor-of-custom-view-twodscrollview – rideintothesun Nov 15 '17 at 15:38

0 Answers0