Share via

My app causes Maui to crash on Android. I have added try/catch everywhere, problem is in Maui somewhere.

Gerry Ha 5 Reputation points
2026-04-18T16:04:19.13+00:00

Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView() on the child's parent first.'

Can someone from the Maui team contact me - my app crashes Maui on Android. It has something to do with ObservableCollection, and is easy to reproduce. Things work just fine for a while, just keep using the app, tapping the screen, then after a bit boom, app dies. I have spent quite a bit of time with Opus trying to find the root of the issue, can't. Running in debug there is no stack trace on the crash, the Android log has nothing helpful, I have try/catch on every bit of code and it is not caught.

The repo is private but I can add someone with a microsoft.com email. Like I say, easy to reproduce, just run it on an Android device and test for a few minutes.

Developer technologies | .NET | .NET MAUI

2 answers

Sort by: Most helpful
  1. Tushar Kanherkar 0 Reputation points
    2026-04-18T19:06:33.3+00:00

    The first crash (IllegalStateException: The specified child already has a parent) happens when the same view is added twice to the Android view hierarchy. That’s usually triggered by ObservableCollection updates in CollectionView or custom templates re‑using views. The fix is to ensure each item creates a new view instance and that old views are properly removed before being re‑added.

    The second error:

    Code

    Error 316 monodroid-assembly Could not load library '.../liblog'. dlopen failed: library not found
    

    is different—it’s coming from the Android runtime. This usually means:

    The app package split (e.g. split_config.arm64_v8a.apk) is missing a native library expected by Mono/MAUI.

    It can happen if the build output is corrupted, or if the APK splits are incomplete on device.

    Steps to try:

    Clean and rebuild the solution, then redeploy.

    Delete the app from the device completely before reinstalling.

    Make sure you’re targeting the correct ABI (arm64‑v8a) in your project settings.

    If you’re using App Bundles (AAB), confirm that the native libraries are included in all splits.

    Test with a Debug build deployed directly (not via Play/App Center) to rule out packaging issues.

    If it persists, create a minimal reproducible sample and file an issue on the official .NET MAUI GitHub repo: https://github.com/dotnet/maui/issues (github.com in Bing). The team can only investigate with a repro.

    Bottom line:

    • The first crash is a view re‑use problem in your UI logic.

    The second crash is a packaging/runtime issue with missing native libraries. Cleaning/rebuilding and checking ABI settings usually resolves it. If not, share a minimal repro with the MAUI team so they can investigate.The first crash (IllegalStateException: The specified child already has a parent) happens when the same view is added twice to the Android view hierarchy. That’s usually triggered by ObservableCollection updates in CollectionView or custom templates re‑using views. The fix is to ensure each item creates a new view instance and that old views are properly removed before being re‑added.

    The second error:

    Code

    Error 316 monodroid-assembly Could not load library '.../liblog'. dlopen failed: library not found
    

    is different—it’s coming from the Android runtime. This usually means:

    The app package split (e.g. split_config.arm64_v8a.apk) is missing a native library expected by Mono/MAUI.

      It can happen if the build output is corrupted, or if the APK splits are incomplete on device.
      
      **Steps to try:**
      
         **Clean and rebuild** the solution, then redeploy.
         
            **Delete the app from the device** completely before reinstalling.
            
               Make sure you’re targeting the correct ABI (arm64‑v8a) in your project settings.
               
                  If you’re using **App Bundles (AAB)**, confirm that the native libraries are included in all splits.
                  
                     Test with a **Debug build deployed directly** (not via Play/App Center) to rule out packaging issues.
                     
                        If it persists, create a **minimal reproducible sample** and file an issue on the official .NET MAUI GitHub repo: `https://github.com/dotnet/maui/issues` (github.com in Bing). The team can only investigate with a repro.
                        
                        **Bottom line:**
                        
                           The first crash is a view re‑use problem in your UI logic.
                           
                              The second crash is a packaging/runtime issue with missing native libraries. Cleaning/rebuilding and checking ABI settings usually resolves it. If not, share a minimal repro with the MAUI team so they can investigate.
                              
    
    1 person found this answer helpful.
    0 comments No comments

  2. Nancy Vo (WICLOUD CORPORATION) 3,465 Reputation points Microsoft External Staff Moderator
    2026-04-20T03:27:17.9966667+00:00

    Hello @Gerry Ha ,

    Thanks for your question.

    The error The specified child already has a parent. You must call removeView() on the child's parent first occurs when MAUI tries to add a UI element to the screen that's already attached somewhere else. In Android, a view can only have ONE parent at a time.

    I recommend the following solutions and code examples:

    1. If you're using CollectionView anywhere in your calendar display, add this attribute to disable view recycling since MAUI will create new view instances instead of reusing old ones:
    <CollectionView RemainingItemsThreshold="-1"
                    ItemsSource="{Binding YourCalendarData}">
        <!--  existing code -->
    </CollectionView>
    
    1. If using ObservableCollection with a calendar view, the problem often occurs when using .Clear() then .Add() in rapid succession: Instead of:
    public void UpdateCalendar()
    {
        Days.Clear();
        foreach (var day in GetNewDays())
        {
            Days.Add(day);
        }
    }
    

    Replace with:

    public void UpdateCalendar()
    {
        var newDays = new ObservableCollection<YourDayType>(GetNewDays());
        Days = newDays;
        OnPropertyChanged(nameof(Days));
    }
    
    1. Use DataTemplate Correctly.

    If your app uses CollectionView, CarouselView, or any templated control:

    <!-- No x:Name, new instance per item -->
    <CollectionView ItemsSource="{Binding Days}">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <StackLayout>
                    <Label Text="{Binding DayNumber}" />
                </StackLayout>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
    

    What about the error 316 mondodroid...?

    -> In most cases, this error occurs because of a MAUI build configuration issue. Furthermore, there are known issues with certain MAUI versions mishandling native library loading on Android (.NET 8).

    I recommend cleaning and rebuilding your project.

    1. In Visual Studio: Build → Clean Solution
    2. Delete these folders manually:
    • bin/ folder
    • obj/ folder
    1. Build → Rebuild Solution
    2. Uninstall the app from the Android device/emulator completely
    3. Redeploy

    I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.