Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android - Event handler BatteryInfoChanged unsubscribe crashes when no subscribe has happened before #18376

Closed
dieterboullart opened this issue Oct 26, 2023 · 1 comment · Fixed by #18386
Assignees
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.6 Look for this fix in 8.0.6 SR1! fixed-in-8.0.10 fixed-in-8.0.14 fixed-in-8.0.40 migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working
Milestone

Comments

@dieterboullart
Copy link

Description

After migration from Xamarin Essentials to MAUI Essentials I got a NullReferenceException on unsubscribing to the event BatteryInfoChanged, because in Batter

In Xamarin Essentials there was a check in the BatteryImplementation.BatteryInfoChanged "remove" code with a variable "wasRunning". For some reason this check was removed in MAUI Essentials. And this causes my code to crash in MAUI Essentials and not in Xamarin Essentials.

The same issue will probably occur with all other events on IBattery.

Steps to Reproduce

Reproduction steps for Android (didn't test on other platforms):

  1. Inject an IBattery dependency in your class constructor.
  2. Call _battery.BatteryInfoChanged -= (sender, args) => { };
  3. Null reference exception occurs in Battery.android.cs on line 66 on batteryReceiver.Dispose() because batteryReceiver has never been initialized.

Link to public reproduction project repository

No response

Version with bug

7.0.96

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android (any version)

Did you find any workaround?

No response

Relevant log output

No response

@dieterboullart dieterboullart added the t/bug Something isn't working label Oct 26, 2023
@jsuarezruiz jsuarezruiz added migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Oct 26, 2023
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Oct 26, 2023
@jsuarezruiz jsuarezruiz self-assigned this Oct 26, 2023
@ghost
Copy link

ghost commented Oct 26, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info fixed-in-8.0.6 Look for this fix in 8.0.6 SR1! fixed-in-8.0.10 fixed-in-8.0.14 fixed-in-8.0.40 migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants