Repository navigation
Description
Description
On Android, changing BindableLayout.ItemsSource on a layout that is currently hidden (an ancestor has IsVisible="False") can throw ObjectDisposedException from ContentViewHandler.DisconnectHandler / BorderHandler.DisconnectHandler. The page is alive and on screen; only the part of it holding the layout is hidden. The platform view of a template child (Microsoft.Maui.Platform.ContentViewGroup) has already been disposed, while the cross-platform child still has its handler, so DisconnectHandlers calls RemoveAllViews() on a disposed peer.
The failure depends on the main thread having been idle. With a repeating one-second Dispatcher.StartTimer that does nothing, it does not occur.
Stack trace
System.ObjectDisposedException: Cannot access disposed object with JniIdentityHashCode=...
Object name: 'Microsoft.Maui.Platform.ContentViewGroup'.
at Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable self)
at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters)
at Android.Views.ViewGroup.RemoveAllViews()
at Microsoft.Maui.Handlers.BorderHandler.DisconnectHandler(ContentViewGroup platformView)
at Microsoft.Maui.Handlers.ViewHandler`2.OnDisconnectHandler(Object platformView)
at Microsoft.Maui.Handlers.ElementHandler.DisconnectHandler(Object platformView)
at Microsoft.Maui.Handlers.ElementHandler.Microsoft.Maui.IElementHandler.DisconnectHandler()
at Microsoft.Maui.ViewExtensions.DisconnectHandlers(IView view)
at Microsoft.Maui.Controls.BindableLayoutController.ClearChildren(IBindableLayout layout)
at Microsoft.Maui.Controls.BindableLayoutController.TryAddEmptyView(IBindableLayout layout, IEnumerator& enumerator)
at Microsoft.Maui.Controls.BindableLayoutController.CreateChildren()
at Microsoft.Maui.Controls.BindableLayoutController.SetItemsSource(IEnumerable itemsSource)
The same happens through ContentViewHandler.DisconnectHandler when the template root is a ContentView instead of containing a Border.
Where we see it
A page with three sections stacked in one Grid, each shown or hidden with IsVisible (a tab layout). Section 1 is a ScrollView with several BindableLayouts; their item templates contain a Border or are ContentViews.
- Show section 1, let it load, scroll it down and back up.
- Switch to section 3 (section 1 becomes
IsVisible="False"). - Wait about 20 seconds without touching the app.
- Set the
ItemsSourceof aBindableLayoutin section 1 tonullor to a new empty collection.
Result: ObjectDisposedException as above. Expected: the children are removed without an exception.
What we checked
- 6 of 6 runs fail with these steps; without the scroll in step 1 it did not fail (1 run).
- Walking the page's visual tree once a second and checking
Handle == IntPtr.Zeroon everyHandler.PlatformViewnever finds a disposed view, and with that watcher running the exception does not occur (3 of 3 runs clean). - A one-second dispatcher timer that does nothing also avoids it (1 run).
- Replacing the
Borderin one template with aBoxViewonly moves the failure to the nextBindableLayoutin the hidden section. - No application code disposes or wraps these native views.
Not done
- No minimal reproduction project yet; the steps above are from a production app.
- We have not identified what disposes the
ContentViewGroup.
Environment
- .NET MAUI 10.0.110,
net10.0-android, Debug build - Android emulator, Pixel, API 36
- Not checked on iOS or on a physical device
Workaround
Catch ObjectDisposedException around the code that changes the ItemsSource and retry when the section is shown again.
Activity
andreashellquist commentedon Nov 20, 2026
I have a minimal repro now, and it changes the description above: the view that throws is not on the visible page. It is a view that was abandoned with its handlers still connected and is still bound to a long-lived view model.
Repro project: https://github.com/andreashellquist/maui-issue-40471-repro (one page, three buttons, about 170 lines)
Repro (Microsoft.Maui.Controls 10.0.110,
net10.0-android, Debug, Mono, emulator API 37 arm64)BindableLayout.ItemsSourcebound to a singleton view model; the item template contains aBorder(or has aContentViewroot).BindingContextis set on the layout itself.DisconnectHandlers(): remove it from its parent (host.Content = null), or pop its page withHandlerDisconnectPolicy.Manual.GC.Collect(); Java.Lang.JavaSystem.Gc();from a background thread (once for the removed view, twice for the popped page).null(or an empty collection) on the view model.Result, 3 of 3 runs for each variant:
ObjectDisposedExceptioninBorderHandler.DisconnectHandlerObjectDisposedExceptioninContentViewHandler.DisconnectHandlerHandlerDisconnectPolicy.ManualWhat happens
After step 2 the only thing that still reaches the layout is the weak reference in
BindingExpression.WeakPropertyChangedProxy. The collection in step 3 takes the Java peers of its views (Handle == 0), but the managed views are still there and the weak reference still resolves. In step 4 the binding applies the new value to the abandoned layout,BindableLayoutController.ClearChildrencallsDisconnectHandlers()on the item views, andBorderHandler.DisconnectHandler/ContentViewHandler.DisconnectHandlercallRemoveAllViews()on the disposedContentViewGroup.One more GC before step 4 makes the exception go away, because the managed views are then collected too. In a real app it therefore shows up only when the change happens between those two collections, which looks random and timing-dependent (that is what I misread as "the UI thread has been idle" in the original report).
LayoutHandler.DisconnectHandleron Android appears to check for a disposed platform view beforeRemoveAllViews()(read onmain), which fits theGrid+BoxViewvariant not throwing.BorderHandlerandContentViewHandlerhave no such check; adding it there would avoid the exception.The exception surfaces in the view model's property setter while a different page is on screen. Hiding the layout, scrolling, waiting, a custom layout,
CollectionViewand images made no difference in the repro.Stack trace from the repro:
NafeelaNazhir commentedon Nov 20, 2026
This issue has been validated in Visual Studio Code 1.147.0 with .NET MAUI versions 11.0.10 and 10.0.130 . It can be reproduced on the Android platform.
Screen.Recording.2026-11-20.at.5.15.44.PM.mov