0

I am using MAUI under .NET 7 and I have a launcher application set as default in Android simulator. The app crashes when it is restarted, but works fine otherwise. The application restarts after closing it, because it is set as the default launcher. I get the following exception:

System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'Google.Android.Material.ImageView.ShapeableImageView'.'

What is the problem and how do I fix it?

MatrixRonny
  • 437
  • 3
  • 11

1 Answers1

0

The MAUI project I am working on is using Dependency Injection and the problem got away after I changed all View dependencies from Singleton to Transient. I had this idea after reading this answer from another post that mentions problems with DI in MAUI.

I didn't find a clear article stating you should define Views as Transient. In my case, the app worked fine with Singleton as long as it was not restarted. I believe it might be a corner case where Android resources are cleared but the View in C# is still there.

MatrixRonny
  • 437
  • 3
  • 11