maui
maui copied to clipboard
System.ObjectDisposedException: ObjectDisposed_Generic ObjectDisposed_ObjectName_Name, Android.OS.PowerManager
Description
When running our application without a charging cable plugged in, the application will crash at any point below 50% battery charge. There is currently no reference the the Battery object. If the application is running and the charging cable is plugged in, the same crash occurs.
Java.Interop.JniPeerMembers.AssertSelf(IJavaPeerable ) Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualBooleanMethod(String , IJavaPeerable , JniArgumentValue* ) Android.OS.PowerManager.get_IsPowerSaveMode() Microsoft.Maui.Devices.BatteryImplementation.get_EnergySaverStatus() Microsoft.Maui.Devices.BatteryImplementation.OnEnergySaverChanged() Microsoft.Maui.Devices.EnergySaverBroadcastReceiver.OnReceive(Context , Intent ) Android.Content.BroadcastReceiver.n_OnReceive_Landroid_content_Context_Landroid_content_Intent_(IntPtr jnienv, IntPtr native__this, IntPtr native_context, IntPtr native_intent) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLL_V(_JniMarshal_PPLL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1)
I believe that a third party component, Shiny Jobs, is disposing the the PowerManager after the battery implementation has retrieved it.
Steps to Reproduce
- Start the app
- Unplug the usb cable
- Wait for the battery info to change
Link to public reproduction project repository
Version with bug
8.0.21
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
Keep the usb cable plugged in
Relevant log output
No response
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Closed similar issues:
- Android - Event handler BatteryInfoChanged unsubscribe crashes when no subscribe has happened before (#18376), similarity score: 0.74
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Updated with repo steps and sample repo
@mattgagnon2 No. I'm disposing of my attachment to a native service. That does not effect others pulling in that instance.
I am just trying to find a solution. You can confirm with the sample app attached and repo steps that the exception is thrown when the trying to get the EnergySaverStatus or when the OnEnergySaverStatusChanged event is run, and if you comment out the line 31 in MauiProgram that registers the job to run, the exception doesn't happen. Shiny has a using statement of
using var pm = this.platform.GetSystemService<Android.OS.PowerManager>(Context.PowerService);
that I thought might be disposing the PowerManager and thus throwing the exception.
Verified this issue with Visual Studio 17.10 Preview 7.0 (8.0.21). Can repro on android platform with sample project.
This is now fixed by https://github.com/dotnet/maui/pull/22281