AsyncRelayCommand causes InvalidOperation_HandleIsNotInitialized crashes in .NET 10 version of MAUI
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 32/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Tranquilo
- Stack tecnológico
- csharp
- Área
- mobile-dev
Línea de trabajo
Comienza con el monitor de tareas de ejecución de AsyncRelayCommand y la ruta de NotifyCanExecuteChanged mostrada en el stack trace, y después examina cómo llega a MAUI Button.IsEnabled a través de CommandElement.GetCanExecute y TypedBinding. Compara el comportamiento de .NET 9 y .NET 10 en Android y Windows; se considera terminado cuando se haya identificado una reproducción fiable o se haya confirmado la interacción desencadenante sin el crash informado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
After upgrading MAUI from .NET 9 version to .NET 10 (specifically 10.0.51), random crashes are reported. I'm not able to reproduce it but the crash rate surged for both Android and Windows (I don't release for iOS/Mac).
There are 2 scenarios that causes the crash:
-
Using any AsyncRelayCommand that prevents concurrent execution (which is the default setting). When the command finishes, it runs NotifyCanExecuteChanged internally. That causes IsEnabled property to a Button that uses the command to be updated and that can randomly cause the app to crash with InvalidOperation_HandleIsNotInitialized. Workaround: I managed to mitigate the crashes by creating the commands with AsyncRelayCommandOptions.AllowConcurrentExecutions option and preventing concurrent execution manually in my code. It added a lot of boiler plate code so I don't like the solution but it definitelly helped.
-
** Calling NotifyCanExecuteChanged() in the code** can unfurtunatelly also crash the app. This is less frequent by the first case but it happends. My workaround was to create a helper method that calls NotifyCanExecuteChanged() on an AsyncRelayCommand but encloses the call in a try..catch block silently catching all exceptions and reporting them. Again, not a great solution, but necessary for .NET MAUI to keep the crash rate back on a .NET 9 level.
I'm not sure what was changed and if the problem is in MVVM toolkit or MAUI.
Example of the stack traces:
android.runtime.JavaProxyThrowable: [System.InvalidOperationException]: InvalidOperation_HandleIsNotInitialized
at System.WeakReference`1[[Microsoft.Maui.Controls.BindableObject, Microsoft.Maui.Controls, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null]].SetTarget + 0x29(Unknown Source:-1)
at Microsoft.Maui.Controls.Internals.TypedBinding`2[[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ApplyToResolvedSource + 0x0(Unknown Source:-1)
at Microsoft.Maui.Controls.Internals.TypedBinding`2[[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Apply + 0xa8(Unknown Source:-1)
at Microsoft.Maui.Controls.BindableObject.ForceBindingApply + 0x27(Unknown Source:-1)
at Microsoft.Maui.Controls.CommandElement.GetCanExecute + 0x43(Unknown Source:-1)
at Microsoft.Maui.Controls.Button.get_IsEnabledCore + 0x8(Unknown Source:-1)
at Microsoft.Maui.Controls.VisualElement.CoerceIsEnabledProperty + 0x16(Unknown Source:-1)
at Microsoft.Maui.Controls.BindableObject.SetValueCore + 0xf7(Unknown Source:-1)
at Microsoft.Maui.Controls.BindableObject.SetValue + 0x55(Unknown Source:-1)
at Microsoft.Maui.Controls.BindableObjectExtensions.RefreshPropertyValue + 0x45(Unknown Source:-1)
at Microsoft.Maui.Controls.VisualElement.RefreshIsEnabledProperty + 0x0(Unknown Source:-1)
at Microsoft.Maui.Controls.Button.Microsoft.Maui.Controls.Internals.ICommandElement.CanExecuteChanged + 0x0(Unknown Source:-1)
at Microsoft.Maui.Controls.WeakCommandSubscription+CommandCanExecuteSubscription.CanExecuteChanged + 0x2c(Unknown Source:-1)
at Unknown.Unknown(Unknown Source:-1)
at CommunityToolkit.Mvvm.Input.AsyncRelayCommand`1+<<set_ExecutionTask>g__MonitorTask|22_0>d[[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext + 0x111(Unknown Source:-1)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw + 0x11(Unknown Source:-1)
at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__124_0 + 0x0(Unknown Source:-1)
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 + 0x0(Unknown Source:-1)
at Java.Lang.Thread+RunnableImplementor.Run + 0x8(Unknown Source:-1)
at Java.Lang.IRunnableInvoker.n_Run + 0x16(Unknown Source:-1)
at mono.java.lang.RunnableImplementor.n_run(RunnableImplementor.java:-2)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:21)
at android.os.Handler.handleCallback(Handler.java:995)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loopOnce(Looper.java:273)
at android.os.Looper.loop(Looper.java:363)
at android.app.ActivityThread.main(ActivityThread.java:10060)
at java.lang.reflect.Method.invoke(Method.java:-2)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
Regression
Not sure. It used to work in .NET 9 version of MAUI and started to crash aftter upgrading to .NET 10.
Steps to reproduce
I cannot reproduce it locally. The AppCenter reports that the app crashes sometimes after an hour if its usage, sometimes just in a few minutes. The crashes are random but too frequent to be ignored.
Expected behavior
No crashes as with the .NET 9 version of MAUI
Screenshots
No response
IDE and version
Other
IDE version
VS2026 (18.5.2)
Nuget packages
- CommunityToolkit.Common
- CommunityToolkit.Diagnostics
- CommunityToolkit.HighPerformance
- CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.4.2
Additional context
No response
Help us help you
No, just wanted to report this
- Lenguaje dominante
- C#
- Estrellas
- 3.8k
- Forks
- 401
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de CommunityToolkit/dotnet
-
bug :bug:
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
CommunityToolkit/dotnet#1206 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
CommunityToolkit/dotnet#648 ·
-
bug :bug:
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
CommunityToolkit/dotnet#1215 ·
-
feature request :mailbox_with_mail:
Dificultad 5/5 Más de una semana Aptitud para principiantes 45/100
CommunityToolkit/dotnet#1214 ·
Todos los issues de CommunityToolkit/dotnet
Issues similares
-
Money ExploitsAbiertoS: Untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
project-wayfarer/wayfarer-14#1628 ·
Los mantenedores suelen responder en 3 días
-
:watch: Not Triaged dotnet-target-version
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
copilot documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 2 días
-
untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
dotnet/dotnet-api-docs#13124 ·
Los mantenedores suelen responder en 1 día
-
agentic-workflows
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día