Skip to content

Bindings invoke disposed ViewModels even though the DataContext was set to null beforehand #11956

@jeanplevesque

Description

@jeanplevesque

Context

Our client complains about (non-fatal) exceptions (thrown from ViewModels) being reported in their diagnostics dashboard.
After some investigation and some attempted fixes, I was able to resolve the issues for the UWP version of the app. However, the mobile version still have the problem.

Current behavior

Basically, the Uno.UI.DataBinding.BindingPropertyHelper invokes properties on some disposed ViewModels, which leads to exceptions.

We tried to fix this by ensuring that we set the DataContext of pages to null before disposing it (the ViewModel).
This seems to work fine on UWP, but not on mobile.

Expected behavior

Mobile behaves like Windows.

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

4.6.44

Affected platforms

Android, iOS

IDE

Visual Studio 2022

IDE version

17.3.6

Relevant plugins

No response

Anything else we need to know?

No response

Metadata

Metadata

Labels

difficulty/challenging 🤯Categorizes an issue for which the difficulty level is reachable with internals understandingkind/bugSomething isn't workingplatform/allCategorizes an issue or PR as relevant to the all platformsproject/binding 🪢Categorizes an issue or PR as relevant to the binding engine

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions