Skip to content

Akka.Hosting: MAUI detection must not throw under InvariantGlobalization - #8783

Merged
Aaronontheweb merged 1 commit into
akkadotnet:devfrom
Aaronontheweb:fix/hosting-maui-detection-invariant-globalization
Oct 6, 2026
Merged

Aaronontheweb merged 1 commit into
akkadotnet:devfrom
Aaronontheweb:fix/hosting-maui-detection-invariant-globalization

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Member

Util.IsRunningInMaui called Assembly.GetName() on every loaded assembly. For a satellite assembly (for example the cs resources that ship with Microsoft.Data.SqlClient), GetName() builds a CultureInfo, which throws CultureNotFoundException when InvariantGlobalization is on. That crashed AddAkka at startup. MAUI detection now reads Assembly.FullName (a plain string) and treats any detection failure as "not MAUI".

Changes

  • Util.cs: split detection into DetectMaui, IsMauiAssembly and IsMauiAssemblyName. The check reads Assembly.FullName and compares the prefix Microsoft.Maui (ordinal), so real MAUI apps are detected the same way as before. Each assembly check and the enumeration are wrapped so a failure returns false. No new reflection, so no new trim/AOT warnings.
  • FriendsOf.cs: InternalsVisibleTo for the new test project.
  • New Akka.Hosting.InvariantGlobalization.Tests project (added to Akka.slnx). It sets InvariantGlobalization=true and builds a real cs satellite assembly from a .resx. It has its own project because invariant mode changes the sort order in the existing LogStateSnapshotSpecs Verify snapshots in Akka.Hosting.Tests.

Testing

  • Without the fix, Should_NotThrow_When_SatelliteAssemblyIsLoadedUnderInvariantGlobalization and Should_ReturnFalse_When_AssemblyEnumerationFails fail with CultureNotFoundException: ... cs is an invalid culture identifier at RuntimeAssembly.GetName. With the fix, all 3 new tests pass.
  • Akka.Hosting.Tests: 155 passed. dotnet build -warnaserror is clean.
  • Akka.Hosting AOT canary (PublishAot, linux-x64): publish succeeds, prints [canary-hosting] OK, and scripts/CheckAotWarnings.cs reports no new trim/AOT warnings.

The same crash reproduces on the JIT with InvariantGlobalization=true, so it is a globalization-mode problem and not specific to AOT.

Breaking changes

None expected. The new methods are internal.

v1.5 has the identical IsRunningInMaui code in src/contrib/hosting/Akka.Hosting/Util.cs, so this needs a backport to v1.5.

Fixes #8782

Util.IsRunningInMaui called Assembly.GetName() on every loaded assembly.
For satellite assemblies that builds a CultureInfo, which throws
CultureNotFoundException when InvariantGlobalization is on. Read
Assembly.FullName instead and treat any detection failure as 'not MAUI'.

Adds Akka.Hosting.InvariantGlobalization.Tests, which runs in invariant
mode and loads a real 'cs' satellite assembly.
@Aaronontheweb Aaronontheweb added this to the 1.6.0 milestone Oct 6, 2026
@Aaronontheweb
Aaronontheweb enabled auto-merge (squash) October 6, 2026 20:08
@Aaronontheweb
Aaronontheweb merged commit a173eb0 into akkadotnet:dev Oct 6, 2026
9 of 16 checks passed
@Aaronontheweb Aaronontheweb added bug akka-hosting Akka.Hosting related issues akka.net v1.6 Akka.NET v1.6-related issues labels Oct 6, 2026
Aaronontheweb added a commit that referenced this pull request Oct 6, 2026
#8783 added InternalsVisibleTo("Akka.Hosting.InvariantGlobalization.Tests") to Akka.Hosting without updating the Hosting API approval, so CoreAPISpec.ApproveHosting fails on dev.
Aaronontheweb added a commit to Aaronontheweb/akka.net that referenced this pull request Oct 6, 2026
…T canary

Assembly.FullName also throws CultureNotFoundException for satellite assemblies
on Native AOT under InvariantGlobalization, so the catch in IsMauiAssembly is
required. Fix the comment, narrow bare catch blocks to catch (Exception).

Add a Czech satellite resource to the Hosting AOT canary so it reproduces the
akkadotnet#8782 crash, and strengthen the InvariantGlobalization tests (hazard canary,
direct FullName assertion, order-independent enumeration test).

Follow-up to akkadotnet#8783, refs akkadotnet#8782
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

akka.net v1.6 Akka.NET v1.6-related issues akka-hosting Akka.Hosting related issues bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Akka.Hosting: startup crash in IsRunningInMaui with InvariantGlobalization (CultureNotFoundException)

1 participant