This repository was archived by the owner on May 1, 2024. It is now read-only.

Description
When a custom renderer is automatically disposed it should trigger a call to OnElementChanged() with a reference to the associated element in the ElementChangedEventArgs under OldElement to allow for any clean-up (i.e. remove event handlers). This is not happening, OnElementChanged() is not called before the renderer is disposed.
Steps to Reproduce
- Create a custom control with an event in the shared project.
- Create a renderer in the Android project using a WebView as the native control.
- In OnElementChanged() when a NewElement is passed in the ElementChangedEventArgs add a handler to the control's event.
- When a OldElement is passed remove the event handler.
- Use the custom control in a ContentPage.
- Navigate away from the page and back to it.
- Invoke the event on the custom control.
Expected Behavior
The event handler is called correctly.
Actual Behavior
Everything works fine until the page is navigated away from and back to. Invoking the event then results in an ObjectDisposedException against the control.
Placing a breakpoint on the OnElementChanged method in the renderer and adding an overridden Dispose method with a breakpoint shows that when the page is navigated away from the Dispose method is called but OnElementChanged is not called. When the page is navigated back to a new renderer instance is created and the OnElementChanged method is called with a NewElement referenced in the ElementChangedEventArgs so an additional event handler is attached.
When the event is invoked the handler for the old renderer instance is still trying to be called which is now disposed.
Basic Information
- Version with issue: Xamarin Forms 4.3.0.908675
- Last known good version:
- IDE: Visual Studio 2019
- Platform Target Frameworks: