Forum Libraries, Components, and Plugins


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

PSA Garbage Collection crash UrhoSurface.Show (Android)

In my project i do some initialization in page constructor and then OnAppearing calls UrhoSurface.Show. If during Show execution a GC run is needed i get a crash with error :

System.NullReferenceException: Object reference not set to an instance of an object. at Urho.Droid.UrhoSurface+<SetSdlMain>c__AnonStorey2.<>m__0 (System.IntPtr _) [0x00000]

I tested it with an empty Urho Application getting created it Show like this:

urhoTest = await urhoSurface.Show<UrhoTest>(new ApplicationOptions(assetsFolder: null) { Orientation = ApplicationOptions.OrientationType.Landscape });

If i add GC.Collect() before calling UrhoSurface.Show everything works without crashes.
I use Urhosharp.Forms 1.2.21 from NuGet, not sure if it is still a problem in the current git hub version.
Just wanted to share this info, not sure if it's a bug or expected behavior.


  • NickWhitehurstNickWhitehurst GBMember ✭✭

    Massive thanks for the GC.Collect() work around!!

    Wasted hours on this, couldn't work out what was causing it.

  • Almost 3 years later... This is still a problem and your workaround saved me hours.

Sign In or Register to comment.