Skip to content

.NET 10 breaks library loading semantics #10617

Closed

Description

@bengt-GS

Android framework version

net10.0-android (Preview)

Affected platform version

.NET 10 RC 2

Description

Hello! We have identified an issue with how .NET loads native libraries, which we believe was introduced since .NET 10. From the release notes we believe "Use Android shared library loader for JNI libraries" (#10376) is the culprit.

Our understanding is that this commit will preload all libraries that define a JNI_OnLoad.

However, this changes the semantics of the code drastically. The example below illustrates this by loading a different library based on an external condition. Note that there are other cases as well but generally this change means that the libraries are always loaded, regardless of whether at that point they should be loaded, or whether the Java code loads them at all.

The change introduced by the aforementioned commit will break this mechanism. I have attached samples that is a stripped down version of a case where we ran into issues due to this change:

  • An android SDK that provides a 'returnTrue()' method (implemented in native). If the correct native library is loaded, this method will return true.
  • A sample android app, written in Java that shows returnTrue() does indeed return true.
  • Bindings for the SDK + a Maui app that uses said bindings. A button can be pressed in the sample which will show that the wrong variant is loaded (as returnTrue() returns false).

Steps to Reproduce

Here are the aforementioned samples:

  1. ExampleNativeLibrary.zip
  2. JavaApp.zip
  3. ExampleLibraryBinding.zip
  4. MauiMainApp.zip
  • Running 'JavaApp' will result in "True? true" being printed in the logcat.
  • Running the 'MauiMainApp' sample will result in "True? false" being printed in the logcat.

This illustrates one of the ways preloading native libraries can result in unexpected behavior.

Did you find any workaround?

No response

Relevant log output

Activity

  1. added
    Area: App Runtime
    needs-triage
    on Nov 27, 2025
  2. self-assigned this
    on Nov 28, 2025
  3. Daedren commented on Feb 5, 2026

    @Daedren

    I got around this with a really cursed method of extracting the .so files from the .aar and having them loaded on the side, but it is a pretty big problem around .NET Android, as I have a lot of external frameworks that are crashing or being loaded in the wrong manner, expecting both Android Context and MauiContext when they don't have it.

    Doing this for everything is a gigantic pain.

  4. locked and limited conversation to collaborators on Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: App Runtimeneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions