Skip to content

Warning: observer object was not disposed manually with Dispose() and Missing Dispose call on local IDisposable (cs/local-not-disposed) #26871

Open
@vikher

Description

@vikher

Description

Environment:

.NET MAUI Version: 8.0.93

JetBrains Rider Version: 2024.1.4

CommunityToolkit.Mvvm: 8.3.2

CommunityToolkit.Maui: 9.1.0

Description:
While performing local debugging on both an Android device (Pixel 6 Pro running Android 14) and an iOS simulator (iPhone 15 running iOS 18), I observed the following warning in the logs:

2024-12-30 17:02:11.680874-0600 Mobile[61441:1411563] Warning: observer object was not disposed manually with Dispose()

This warning seems to stem from an ObservableCollection that is loaded after performing a pull-to-refresh operation.

Expected Behavior:
No warnings regarding observer objects not being disposed manually should appear in the logs.

Actual Behavior:
The warning is repeatedly logged, indicating potential resource management issues.

Additional Context:

Observed both in local debugging and Azure DevOps Advanced Security Code Scanning.

Appears linked to ObservableCollection updates after pull-to-refresh.

Image

Missing Dispose call on local IDisposable (cs/local-not-disposed)

Additionally, Azure DevOps Advanced Security Code Scanning is flagging similar warnings in the following generated source files:

Image

Steps to Reproduce

Run the application on an Android Pixel 6 Pro or iOS iPhone 15 Simulator.

Perform a pull-to-refresh action on a screen utilizing an ObservableCollection.

Observe logs in JetBrains Rider or Console.

Link to public reproduction project repository

https://github.com/vikher/testmedia/tree/main/testmedia

Version with bug

8.0.93 SR9.3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

No response

Affected platforms

iOS, Android

Affected platform versions

Device (Android): Pixel 6 Pro (Android 14) Device (iOS Simulator): iPhone 15 (iOS 18)

Did you find any workaround?

No response

Relevant log output

Additionally, Azure DevOps Advanced Security Code Scanning is flagging similar warnings in the following generated source files:

Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/ButtonTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/DatePickerTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/InputViewTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/PickerTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/LabelTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/EntryTextColorTo.g.shared.cs:40

Metadata

Metadata

Assignees

Labels

area-architectureIssues with code structure, SDK structure, implementation detailsplatform/ioss/triagedIssue has been reviewedt/bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions