Xamarin.forms: [Bug] PushModalAsync modal page with Entry crashes on close for MacOS (NRE)

Created on 9 Oct 2019  路  5Comments  路  Source: xamarin/Xamarin.Forms

Description

Call PushModalAsync to show a modal page containing an Entry control. Close the page. The app will crash.

Steps to Reproduce

  1. Create a Xamarin Forms project from template
  2. Add the Mac project to it as per document: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/other/mac
  3. Add a page that can be used for a modal flow, and which contains an Entry control, and call Navigation.PushModalAsync to bring it up.
  4. Run the app. Bring up the modal, close it.

Expected Behavior

Modal closes without problem.

Actual Behavior

System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Platform.MacOS.EntryRenderer.SetAccessibilityLabel () [0x0002c] in <7bc93742592948de80da3cf37e3bec58>:0
at Xamarin.Forms.Platform.MacOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x00190] in <7bc93742592948de80da3cf37e3bec58>:0 at Xamarin.Forms.Platform.MacOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x0008c] in <7bc93742592948de80da3cf37e3bec58>:0
at Xamarin.Forms.Platform.MacOS.ViewRenderer2[TView,TNativeView].Dispose (System.Boolean disposing) [0x0005c] in <7bc93742592948de80da3cf37e3bec58>:0 at Xamarin.Forms.Platform.MacOS.EntryRenderer.Dispose (System.Boolean disposing) [0x00018] in <7bc93742592948de80da3cf37e3bec58>:0 at Foundation.NSObject.Dispose () [0x00001] in /Library/Frameworks/Xamarin.Mac.framework/Versions/6.2.0.47/src/Xamarin.Mac/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.MacOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in <7bc93742592948de80da3cf37e3bec58>:0 at Xamarin.Forms.Platform.MacOS.VisualElementPackager.Dispose () [0x00000] in <7bc93742592948de80da3cf37e3bec58>:0 at Xamarin.Forms.Platform.MacOS.PageRenderer.Dispose (System.Boolean disposing) [0x00071] in <7bc93742592948de80da3cf37e3bec58>:0 at Foundation.NSObject.Dispose () [0x00001] in /Library/Frameworks/Xamarin.Mac.framework/Versions/6.2.0.47/src/Xamarin.Mac/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.MacOS.DisposeHelpers.DisposeModalAndChildRenderers (Xamarin.Forms.Element view) [0x00041] in <7bc93742592948de80da3cf37e3bec58>:0 at Xamarin.Forms.Platform.MacOS.ModalPageTracker+<>c__DisplayClass13_0.<HideModalAsync>b__0 () [0x00000] in <7bc93742592948de80da3cf37e3bec58>:0 at Xamarin.Forms.Platform.MacOS.NSViewControllerExtensions+<>c__DisplayClass0_01[T].b__0 () [0x0001b] in <7bc93742592948de80da3cf37e3bec58>:0
at ObjCRuntime.Trampolines+SDAction.Invoke (System.IntPtr block) [0x0001c] in /Library/Frameworks/Xamarin.Mac.framework/Versions/6.2.0.47/src/Xamarin.Mac/Trampolines.g.cs:13463
at at (wrapper native-to-managed) ObjCRuntime.Trampolines+SDAction.Invoke(intptr)
at at (wrapper managed-to-native) AppKit.NSApplication.NSApplicationMain(int,string[])
at AppKit.NSApplication.Main (System.String[] args) [0x00040] in /Library/Frameworks/Xamarin.Mac.framework/Versions/6.2.0.47/src/Xamarin.Mac/AppKit/NSApplication.cs:100
at PushModal.Mac.MainClass.Main (System.String[] args) [0x00017] in /Users/denniswelu/Projects/_Sandbox/PushModal/PushModal.Mac/Main.cs:11

Basic Information

  • Version with issue: 4.3.0-pre3
  • Last known good version: ?
  • IDE: VS for Mac
  • Platform Target Frameworks:

    • MacOS: 10.14

Reproduction Link

PushModal.zip

Additional Info

This is a follow-up issue while testing https://github.com/xamarin/Xamarin.Forms/issues/6866 . The only difference in the repro solution is the addition of a single line to the ModalPage.xaml:

    <Entry Placeholder="Enter something here" WidthRequest="200" HorizontalOptions="Center" VerticalOptions="Center"/>

A workaround is possible by creating a derived EntryRenderer and overriding SetAccessibilityLabel:

        protected override void SetAccessibilityLabel()
        {
            if (Control != null)
                base.SetAccessibilityLabel();
        }
1 in-progress macOS bug

All 5 comments

Added a PR to fix this, thanks for reporting!

Awesome, amazing turnaround time there @jfversluis :-)

Did this change make it into the just-released 4.3.0 NuGet?
I'm getting that same exception using Xamarin.Forms 4.3.0.908675.

I think it just missed it. Sorry about that!

Be on the lookout for 4.4-pre1 which should be here soon or the first 4.3 service release that should definitely have this change

Closed by #7900

Was this page helpful?
0 / 5 - 0 ratings