runtime: [Android] App crashing with condition `xref_count == xref_index' not met

Description

This is happening when using shell navigation to navigate to a bunch of pages. Unfortunately I was unable to reproduce it on a simpler project to post. So I’m uncertain exactly what’s causing this. However, it was working on MAUI version 8.0.40 and broke on subsequent versions.

I was able to reproduce on the Android emulator

Others have posted about this as well: https://github.com/dotnet/maui/issues/23827 https://github.com/dotnet/maui/discussions/23634 https://github.com/dotnet/maui/discussions/23826

Steps to Reproduce

See description

Link to public reproduction project repository

No response

Version with bug

8.0.60 SR6

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.40 SR5

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

[namix.mobileapp] * Assertion at /__w/1/s/src/mono/mono/metadata/sgen-tarjan-bridge.c:1174, condition `xref_count == xref_index' not met, function:processing_build_callback_data, xref_count is 1101 but we added 1096 xrefs
[libc] Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 8651 (namix.mobileapp), pid 8651 (namix.mobileapp)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 5
  • Comments: 64 (31 by maintainers)

Commits related to this issue

Most upvoted comments

The fix is going to be released with .NET 9.0.5 (±May 13, 2025).

We were able to fix the issue using the suggestion above. We added an Environment.txt file with the following: MONO_GC_PARAMS=bridge-implementation=new

And added this to the project file:

  <ItemGroup>
    <AndroidEnvironment Include="Platforms\Android\Environment.txt" />
  </ItemGroup>

do you know by now, when will this fix be available?

The current target release is 9.0.6, so roughtly June 10, 2025.

The fix is going to be released with .NET 9.0.5 (±May 13, 2025).

Note that the fix in servicing had to be reverted because we hit an assertion in testing. That was fixed by https://github.com/dotnet/runtime/pull/114637, but it caused us to be a bit more careful before we take the fix in. If https://github.com/dotnet/runtime/pull/114682 goes in, that’ll apply to 9.0.6.

I’ll reopen the issue for better tracking.

A fix is being worked on. Until it is released, you can use the workaround in https://github.com/dotnet/runtime/issues/106410#issuecomment-2391391866.

.NET 9.0.7 fixed this for us. App used to crash when working with images (usually during or after uploading). Doesn’t crash anymore. Thanks!

@ dotnet-runtime maintainers: how risky would it be - in your opinion - to use a daily build for a production app given the current state of 9.x?

./dotnet-install.sh --dry-run --channel 9.0.3xx --quality daily

dotnet-install: Payload URLs:
dotnet-install: URL #0 - aka.ms: https://ci.dot.net/public/Sdk/9.0.302-servicing.25316.19/dotnet-sdk-9.0.302-osx-arm64.tar.gz
dotnet-install: Repeatable invocation: ./dotnet-install.sh --version "9.0.302-servicing.25316.19" --install-dir "/Users/alberto.aldegheri/.dotnet" --architecture "arm64" --os "osx" --quality "daily"

We really need this fix asap and the 9.0.7 release time doesn’t meet our deadlines.

Image Still got the same error after upgrade dotnet SDK version to 9.0.6

If the backport of tests is not too complicates (like needed lot of other infra changes) then I would also pick it up. As you noted we will maintain 9.0 for at least another year, so we should be able to validate that it works well.

I’d prefer backporting the tests as well so we’re sure it works in the 9.0 state-of-the-world

Do you know, by any chance, what is the timeline for a release fixing this issue?

Unfortuantely, no. It’s likely that my fix will get reviewed this week. However, even if it gets accepted as-is we will need to go through a backport process to fix it in .NET 9. Once we are at that point I can make some estimates.

Thats a great find! I am actually also using tintbehavior from CommunityToolkit in my project and I also experienced this issue. This should be flagged in the CommunityToolkit as well if thats truly the culprit.

It’s NOT the culprit. The bug is in the MonoVM GC bridge. It just happens to be triggered by certain shapes of the object reference graph, so some code may be more prone to trigger it.

This is probably dotnet/android#9701. Someone there mentioned <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk> as a workaround but that is a bit weird since it should be the default in Release configufation.

So when I added this:

<PropertyGroup Condition="$(TargetFramework.Contains('-android'))">
	<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
</PropertyGroup>

My code now shows this: [DOTNET] MONO_GC_PARAMS: bridge-implementation=new

Debugging seems to be running better now without crashing but I am still testing. It was really slow starting the debugger tho.

I am also facing this:

  • Assertion at /__w/1/s/src/mono/mono/metadata/sgen-tarjan-bridge.c:1176, condition xref_count == xref_index' not met, function:processing_build_callback_data, xref_count is 572 but we added 563 xrefs [monodroid] * Assertion at /__w/1/s/src/mono/mono/metadata/sgen-tarjan-bridge.c:1176, condition xref_count == xref_index’ not met, function:processing_build_callback_data, xref_count is 572 but we added 563 xrefs [monodroid] Abort at mono-log-adapter.cc:46:3 (‘static void xamarin::android::internal::MonodroidRuntime::mono_log_handler(const char *, const char *, const char *, mono_bool, void *)’)

Unfortunatly I don’t have a simplified repro

Using: .NET MAUI 9.0.5


Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------------------------
android                    35.0.39/9.0.100        VS 17.14.35806.103, VS 17.13.35828.75
ios                        18.2.9180/9.0.100      VS 17.14.35806.103, VS 17.13.35828.75
maccatalyst                18.2.9180/9.0.100      VS 17.14.35806.103, VS 17.13.35828.75
maui-windows               9.0.14/9.0.100         VS 17.14.35806.103, VS 17.13.35828.75