dotnet / dotnet/android

Android runtime exception - Cannot create instance of type '': no Java peer type found.

Open
#12,012 0 comments 0 reactions 0 assignees View on GitHub
Area: App Runtime needs-triage
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 21h
Merged PRs (30d)
257

Description

### Android framework version

net10.0-android

### Affected platform version

VS 2026 18.7.3, NET 10.0.301, .NET Android 36.1.69

### Description

With the Android workload **36.1.69** (which includes the #11208 / #11248 fixes), `FindJavaObjectsStep` still emits an empty `.jlo.xml` for a binding assembly when:

1. an Android `Java.Lang.Object`-derived type has its **base class in a *second* multi-TFM assembly**, and
2. a **net-only** (non-Android) project reference drags a non-Android copy of that second assembly onto the build's assembly search path.

The resolver name-binds the base type to the non-Android copy (where the type isn't compiled in — it's `#if ANDROID`), fails to recognize the derived type as a Java type, produces ``, generates no Java Callable Wrapper, and the app throws at launch:

```
System.NotSupportedException: Cannot create instance of type
'MultiTfmClassLibrary1.AndroidDerivedObject': no Java peer type found.
```

#11208 loads the *primary* scanned assembly by path, but does not stop **name-based base-type resolution** from binding to the stray non-Android copy.

This issue does not happen in .NET 9, and is making it difficult for us to migrate to .NET 10.

Repro project: [NoJavaPeerTypeFound.zip](https://github.com/user-attachments/files/29765699/NoJavaPeerTypeFound.zip)

### Steps to Reproduce

I attached a solution with this structure:

```
AndroidApp (net10.0-android)
├── direct ─────────────► MultiTfmClassLibrary1 (net10.0;net10.0-android)
│ └── AndroidDerivedObject : MultiTfmClassLibrary2.AndroidObject (#if ANDROID)
├── direct ─────────────► MultiTfmClassLibrary2 (net10.0;net10.0-android)
│ └── AndroidObject : Java.Lang.Object (#if ANDROID)
└──► ClassLibrary (net10.0 ONLY) ──► MultiTfmClassLibrary1 ← the poison:
its net10.0 output copies
non-Android MultiTfmClassLibrary1.dll
+ MultiTfmClassLibrary2.dll onto
the search path
```

`MainActivity.OnCreate`:

```csharp
var obj = new MultiTfmClassLibrary1.AndroidDerivedObject(); // throws at launch
```

### Did you find any workaround?

Add the Android TFM to every net-only library that (transitively) references an Android-bearing binding assembly:

```xml
net10.0;net10.0-android
```

Or downgrade to .NET 9.

### Relevant log output

```shell
07-07 14:30:39.448 E/AndroidRuntime( 6407): FATAL EXCEPTION: main
07-07 14:30:39.448 E/AndroidRuntime( 6407): Process: com.companyname.AndroidApp, PID: 6407
07-07 14:30:39.448 E/AndroidRuntime( 6407): android.runtime.JavaProxyThrowable: [System.NotSupportedException]: Cannot create instance of type 'MultiTfmClassLibrary1.AndroidDerivedObject': no Java peer type found.
07-07 14:30:39.448 E/AndroidRuntime( 6407): at Java.Interop.JniPeerMembers+JniInstanceMethods..ctor + 0x3b(Unknown Source)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at Java.Interop.JniPeerMembers+JniInstanceMethods.GetConstructorsForType + 0x41(Unknown Source)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at Java.Interop.JniPeerMembers+JniInstanceMethods.StartCreateInstance + 0x25(Unknown Source)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at Java.Lang.Object..ctor + 0x1a(Unknown Source)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at MultiTfmClassLibrary2.AndroidObject..ctor(Unknown Source)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at MultiTfmClassLibrary1.AndroidDerivedObject..ctor(Unknown Source)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at AndroidApp.MainActivity.OnCreate(C:\Users\connor.brown\Documents\Projects\NoJavaPeerTypeFound\NoJavaPeerTypeFound\AndroidApp\MainActivity.cs:15)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ + 0xe(Unknown Source)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at crc64e75cd28e16296800.MainActivity.n_onCreate(Native Method)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at crc64e75cd28e16296800.MainActivity.onCreate(MainActivity.java:28)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.Activity.performCreate(Activity.java:9155)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.Activity.performCreate(Activity.java:9133)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1524)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4265)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4470)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2826)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.os.Handler.dispatchMessage(Handler.java:110)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.os.Looper.loopOnce(Looper.java:248)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.os.Looper.loop(Looper.java:338)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at android.app.ActivityThread.main(ActivityThread.java:9137)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at java.lang.reflect.Method.invoke(Native Method)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
07-07 14:30:39.448 E/AndroidRuntime( 6407): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with FindJavaObjectsStep and the attached NoJavaPeerTypeFound.zip reproduction, focusing on name-based base-type resolution when the net-only assembly is on the search path. Compare the generated .jlo.xml and Java Callable Wrapper output before and after the fix, then launch AndroidApp and confirm AndroidDerivedObject can be created without the no-Java-peer-type exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, csharp
Domain
build-system, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.