androidcrashmauiobservablecollection

App Crash when run on the device itself, but when it is connected to the debug mode works fine


I'm developing an app to handle an inventory for Android, when it run on the device itself crash (I'm using a Samsung S 20+ and A 21S, but if it is connected to the visual studio on debug mode it works fine, the form it is a collectionview tie to an observable collection, the view model has 2 set of variables on which contain all records and the other handle the filters, on the initial both has the same sub set of data (No filter apply), but when i set the value of the second (which is the one used on the CollectionView) the app crash.

Using .NET Maui 8.0.60 and the target it is 14v min Version 10

    public InventoryViewModel()
    {
        if (string.IsNullOrEmpty(Title))
            Title = "Inventario";
        SelectionMode = SelectionMode.Multiple;
        LoadInventory();
    }

    public void LoadInventory()
    {
        try
        {
            Inventory = new ObservableCollection<ProductsModel>();
            Inventory.Add(new ProductsModel { ProductId = 1, ProductName = "Perfume 1", ProductCategory = "P", Quantity = 1, UnitPrice = 3.53M, BarCode = "1234", IsImageOnServer = false });
            Inventory.Add(new ProductsModel { ProductId = 2, ProductName = "Perfume 2", ProductCategory = "P", Quantity = 2, UnitPrice = 4.63M, BarCode = "5697", IsImageOnServer = false });
            Inventory.Add(new ProductsModel { ProductId = 3, ProductName = "Perfume 3", ProductCategory = "P", Quantity = 3, UnitPrice = 5.73M, BarCode = "8741", IsImageOnServer = false });
            Inventory.Add(new ProductsModel { ProductId = 4, ProductName = "Perfume 4", ProductCategory = "P", Quantity = 2, UnitPrice = 6.83M, BarCode = "9965", IsImageOnServer = false });

            SearchResults = Inventory;   // Here is where the app crashes
        }
        catch (Exception)
        {
            throw;
        }
    }

I have been trying:

  1. Define the observable collection and then add records to it
  2. Assigning directly to the observable collection the values of the first, then the second.
  3. Create a List<ProductusModel> then convert to observable.
  4. Also, install the app on release mode on the phone.

Adding some delay when declare and then adding the data, thinking it was a time issue, but not luck.

Here is the stack code:

    Time    Device Name Type    PID Tag Message
    06-27 23:16:36.573  Samsung SM-A217M    Error   11830   AndroidRuntime  Process: com.gperfumes.crm, PID: 11830
    06-27 23:16:36.607  Samsung SM-A217M    Warning 5368    WindowManager   Prepare app transition: mNextAppTransitionRequests=[TRANSIT_CLOSE, TRANSIT_CLOSE, TRANSIT_CLOSE], mNextAppTransitionFlags=TRANSIT_FLAG_APP_CRASHED, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6369 com.android.server.wm.DisplayContent.prepareAppTransition:6364 com.android.server.wm.ActivityRecord.finishIfPossible:3650 com.android.server.wm.ActivityRecord.finishIfPossible:3456 com.android.server.wm.Task.finishTopCrashedActivityLocked:8918 
    06-27 23:16:36.606  Samsung SM-A217M    Debug   5368    SGM:GameManager sendFocusOutConditionally() - mPrevNotiPkg: (unknown), userId: 0
    handleTaskFocused(), pkgName: com.sec.android.app.launcher, userID:0 mResumedPkgMap does not containsKey.
    06-27 23:16:36.606  Samsung SM-A217M    Debug   5368    SGM:GameManager handleTaskFocused().
    06-27 23:16:36.606  Samsung SM-A217M    Debug   5368    SGM:GameManager onLooperPrepared(), msg: MSG_TASK_FOCUSED, pkgName: com.sec.android.app.launcher, userId: 0
    06-27 23:16:36.605  Samsung SM-A217M    Debug   5368    SGM:GameManager TaskStackListener.onTaskFocusChanged(), taskId=23936, focused=true
    sendRunningComponentFocus(), pkgName: com.sec.android.app.launcher, userId: 0
    06-27 23:16:36.605  Samsung SM-A217M    Debug   5368    SGM:GameManager TaskStackListener.onTaskFocusChanged(), taskId=23965, focused=false
    06-27 23:16:36.605  Samsung SM-A217M    Debug   5368    StatusBarManagerService notifyRequestedSystemKey recent=false home=false
    06-27 23:16:36.605  Samsung SM-A217M    Debug   5368    MARsPolicyManager   onPackageResumedFG pkgName = com.gperfumes.crm, userId = 0
    06-27 23:16:36.605  Samsung SM-A217M    Verbose 5368    WindowManager   Changing focus from Window{dd96dcb u0 com.gperfumes.crm/crc646584e998dbc9d4ac.MainActivity} to null displayId=0 Callers=com.android.server.wm.RootWindowContainer.updateFocusedWindowLocked:583 com.android.server.wm.WindowManagerService.updateFocusedWindowLocked:6497 com.android.server.wm.ActivityTaskManagerService.setResumedActivityUncheckLocked:5498 com.android.server.wm.ActivityRecord.moveFocusableActivityToTop:3364 
    06-27 23:16:36.603  Samsung SM-A217M    Debug   5368    InputDispatcher Focused application set to (0): 99e7e90
    06-27 23:16:36.602  Samsung SM-A217M    Warning 5368    WindowManager   Prepare app transition: mNextAppTransitionRequests=[TRANSIT_CLOSE, TRANSIT_CLOSE], mNextAppTransitionFlags=TRANSIT_FLAG_APP_CRASHED, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6369 com.android.server.wm.DisplayContent.requestTransitionAndLegacyPrepare:6384 com.android.server.wm.Task.finishTopCrashedActivityLocked:8917 com.android.server.wm.RootWindowContainer.lambda$finishTopCrashedActivities$20:2781 com.android.server.wm.RootWindowContainer$$ExternalSyntheticLambda30.accept:10 
    06-27 23:16:36.601  Samsung SM-A217M    Warning 5368    WindowManager   Prepare app transition: mNextAppTransitionRequests=[TRANSIT_CLOSE], mNextAppTransitionFlags=TRANSIT_FLAG_APP_CRASHED, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6369 com.android.server.wm.Task.finishTopCrashedActivityLocked:8916 com.android.server.wm.RootWindowContainer.lambda$finishTopCrashedActivities$20:2781 com.android.server.wm.RootWindowContainer$$ExternalSyntheticLambda30.accept:10 com.android.server.wm.Task.forAllTasks:5181 
    06-27 23:16:36.599  Samsung SM-A217M    Warning 5368    ContextImpl Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1242 com.android.server.am.AppErrors.crashApplicationInner:724 com.android.server.am.AppErrors.crashApplication:584 com.android.server.am.ActivityManagerService.handleApplicationCrashInner:9793 com.android.server.am.ActivityManagerService.handleApplicationCrash:9672 
    Force finishing activity com.gperfumes.crm/crc646584e998dbc9d4ac.MainActivity
    06-27 23:16:36.599  Samsung SM-A217M    Warning 5368    ActivityManager crash : com.gperfumes.crm,10338
    06-27 23:16:36.598  Samsung SM-A217M    Debug   5368    Debug   low && ship && 3rdparty app crash, do not dump
    06-27 23:16:36.598  Samsung SM-A217M    Info    5368    DropBoxManagerService   add tag=data_app_crash isTagEnabled=true flags=0x2
    06-27 23:16:36.593  Samsung SM-A217M    Info    11830   MonoDroid   
    06-27 23:16:36.593  Samsung SM-A217M    Info    11830   MonoDroid   android.runtime.JavaProxyThrowable: [System.Reflection.TargetInvocationException]: Arg_TargetInvocationException
        at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Unknown Source:0)
        at System.RuntimeType.CreateInstanceMono(Unknown Source:0)
        at System.RuntimeType.CreateInstanceDefaultCtor(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing+TypeRouteFactory.GetOrCreate(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing.GetOrCreateContent(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection.GetOrCreateFromRoute(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection+<GoToAsync>d__65.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellNavigationManager+<GoToAsync>d__14.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at CRM.ViewModels.InventoryViewModel+<>c+<<get_EditProductCommand>b__41_0>d.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0(Unknown Source:0)
        at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0(Unknown Source:0)
        at Java.Lang.Thread+RunnableImplementor.Run(Unknown Source:0)
        at Java.Lang.IRunnableInvoker.n_Run(Unknown Source:0)
        at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(Unknown Source:0)
        at mono.java.lang.RunnableImplementor.n_run(Native Method)
        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
    06-27 23:16:36.593  Samsung SM-A217M    Info    11830   MonoDroid   
    --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---
    06-27 23:16:36.592  Samsung SM-A217M    Info    11830   MonoDroid   android.runtime.JavaProxyThrowable: [System.Reflection.TargetInvocationException]: Arg_TargetInvocationException
        at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Unknown Source:0)
        at System.RuntimeType.CreateInstanceMono(Unknown Source:0)
        at System.RuntimeType.CreateInstanceDefaultCtor(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing+TypeRouteFactory.GetOrCreate(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing.GetOrCreateContent(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection.GetOrCreateFromRoute(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection+<GoToAsync>d__65.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellNavigationManager+<GoToAsync>d__14.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at CRM.ViewModels.InventoryViewModel+<>c+<<get_EditProductCommand>b__41_0>d.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0(Unknown Source:0)
        at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0(Unknown Source:0)
        at Java.Lang.Thread+RunnableImplementor.Run(Unknown Source:0)
        at Java.Lang.IRunnableInvoker.n_Run(Unknown Source:0)
        at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(Unknown Source:0)
        at mono.java.lang.RunnableImplementor.n_run(Native Method)
        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
    06-27 23:16:36.592  Samsung SM-A217M    Info    11830   MonoDroid   
    --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---
    06-27 23:16:36.592  Samsung SM-A217M    Info    11830   MonoDroid   Android.Runtime.JavaProxyThrowable: Exception_WasThrown, Android.Runtime.JavaProxyThrowable
    06-27 23:16:36.584  Samsung SM-A217M    Info    11830   MonoDroid   UNHANDLED EXCEPTION:
    06-27 23:16:36.582  Samsung SM-A217M    Warning 11830   monodroid-assembly  Shared library 'liblog' not loaded, p/invoke '__android_log_print' may fail
    06-27 23:16:36.573  Samsung SM-A217M    Error   11830   AndroidRuntime  android.runtime.JavaProxyThrowable: [System.Reflection.TargetInvocationException]: Arg_TargetInvocationException
        at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Unknown Source:0)
        at System.RuntimeType.CreateInstanceMono(Unknown Source:0)
        at System.RuntimeType.CreateInstanceDefaultCtor(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at System.Activator.CreateInstance(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing+TypeRouteFactory.GetOrCreate(Unknown Source:0)
        at Microsoft.Maui.Controls.Routing.GetOrCreateContent(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection.GetOrCreateFromRoute(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellSection+<GoToAsync>d__65.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at Microsoft.Maui.Controls.ShellNavigationManager+<GoToAsync>d__14.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Unknown Source:0)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Unknown Source:0)
        at CRM.ViewModels.InventoryViewModel+<>c+<<get_EditProductCommand>b__41_0>d.MoveNext(Unknown Source:0)
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Unknown Source:0)
        at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0(Unknown Source:0)
        at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0(Unknown Source:0)
        at Java.Lang.Thread+RunnableImplementor.Run(Unknown Source:0)
        at Java.Lang.IRunnableInvoker.n_Run(Unknown Source:0)
        at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(Unknown Source:0)
        at mono.java.lang.RunnableImplementor.n_run(Native Method)
        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:31)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Solution

  • and thank you to everyone for their comments, with them, I was able to find the solution to my problem.

    The problem was in the XAML Code not in the C#, there was a wrong reference on the collectionview, I pointed to a reference to a nonexistent name.

    I read all this post, and on it someone refer to a non-existing Color name, I start comment out all the controls and then enable one by one (on the XAML) until I find out the root cause (I did not play with this because I thought the problem resided on the C# code instead of the XAML)

                            <SwipeView.RightItems>
                                <SwipeItems Mode="Reveal">
                                    <SwipeItem Text="Editar" 
                                               BackgroundColor="#4CAF50"
                                               IconImageSource="{FontImage FontFamily='AwesomeIcons', Glyph={x:Static FontHelpers:FontHelperAwesome.Pencil}, Size=30, Color=LightGreen}" 
                                               Command="{Binding BindingContext.EditTransactionCommand, **Source={x:Reference TransactionStatementCollectionView}}"** //This reference was pointing to the wrong name 
                                               CommandParameter="{Binding .}" />
                                </SwipeItems>
                            </SwipeView.RightItems>