Skip to content

Commit 8518ee0

Browse files
[Mono.Android] update more TypeManager.GetClassName() calls (#9865)
Context: #9846 `Mono.Android` has various test failures under NativeAOT such as: I NUnit : CastJavaLangObjectArrayToByteArrayThrows E NUnit : [FAIL] E NUnit : : Expected: <System.InvalidCastException> E NUnit : But was: <System.DllNotFoundException> (DllNotFound_Linux, xa-internal-api, E NUnit : dlopen failed: library "xa-internal-api.so" not found E NUnit : dlopen failed: library "libxa-internal-api.so" not found E NUnit : dlopen failed: library "xa-internal-api" not found E NUnit : dlopen failed: library "libxa-internal-api" not found E NUnit : ) E NUnit : at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x4c E NUnit : at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x134 E NUnit : at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x40 E NUnit : at Android.Runtime.RuntimeNativeMethods.monodroid_TypeManager_get_java_class_name(IntPtr klass) + 0x2c E NUnit : at Java.Interop.TypeManager.GetClassName(IntPtr) + 0x10 E NUnit : at Android.Runtime.JNIEnv.AssertCompatibleArrayTypes(IntPtr, Type) + 0x58 E NUnit : at Android.Runtime.JNIEnv.GetArray[T](IntPtr array_ptr) + 0x24 E NUnit : at Java.LangTests.ObjectArrayMarshaling.<>c__DisplayClass0_0.<CastJavaLangObjectArrayToByteArrayThrows>b__0() + 0x18 E NUnit : at NUnit.Framework.Assert.Throws(IResolveConstraint, TestDelegate, String, Object[]) + 0xc4 E NUnit : at Java.LangTests.ObjectArrayMarshaling.CastJavaLangObjectArrayToByteArrayThrows() + 0x150 E NUnit : at libMono.Android.NET-Tests!<BaseAddress>+0x152f704 E NUnit : at System.Reflection.DynamicInvokeInfo.Invoke(Object, IntPtr, Object[], BinderBundle, Boolean) + 0x10c I updated the remaining calls in `JNIEnv.cs` to use `JniEnvironment.Types.GetJniTypeNameFromClass()` instead.
1 parent eed1ba2 commit 8518ee0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Mono.Android/Android.Runtime/JNIEnv.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static unsafe void InvokeConstructor (IntPtr instance, string jniCtorSign
205205
IntPtr ctor = JNIEnv.GetMethodID (lrefClass, "<init>", jniCtorSignature);
206206
if (ctor == IntPtr.Zero)
207207
throw new ArgumentException (FormattableString.Invariant (
208-
$"Could not find constructor JNI signature '{jniCtorSignature}' on type '{Java.Interop.TypeManager.GetClassName (lrefClass)}'."));
208+
$"Could not find constructor JNI signature '{jniCtorSignature}' on type '{JniEnvironment.Types.GetJniTypeNameFromClass (new JniObjectReference (lrefClass))}'."));
209209
CallNonvirtualVoidMethod (instance, lrefClass, ctor, constructorParameters);
210210
} finally {
211211
DeleteLocalRef (lrefClass);
@@ -223,7 +223,7 @@ public static unsafe IntPtr CreateInstance (IntPtr jniClass, string signature, J
223223
IntPtr ctor = JNIEnv.GetMethodID (jniClass, "<init>", signature);
224224
if (ctor == IntPtr.Zero)
225225
throw new ArgumentException (FormattableString.Invariant (
226-
$"Could not find constructor JNI signature '{signature}' on type '{Java.Interop.TypeManager.GetClassName (jniClass)}'."));
226+
$"Could not find constructor JNI signature '{signature}' on type '{JniEnvironment.Types.GetJniTypeNameFromClass (new JniObjectReference (jniClass))}'."));
227227
return JNIEnv.NewObject (jniClass, ctor, constructorParameters);
228228
}
229229

@@ -543,7 +543,7 @@ static void AssertCompatibleArrayTypes (Type sourceType, IntPtr destArray)
543543
try {
544544
if (!IsAssignableFrom (grefSource, lrefDest)) {
545545
throw new InvalidCastException (FormattableString.Invariant (
546-
$"Unable to cast from '{Java.Interop.TypeManager.GetClassName (grefSource)}' to '{Java.Interop.TypeManager.GetClassName (lrefDest)}'."));
546+
$"Unable to cast from '{JniEnvironment.Types.GetJniTypeNameFromClass (new JniObjectReference (grefSource))}' to '{JniEnvironment.Types.GetJniTypeNameFromClass (new JniObjectReference (lrefDest))}'."));
547547
}
548548
} finally {
549549
DeleteGlobalRef (grefSource);
@@ -558,7 +558,7 @@ static void AssertCompatibleArrayTypes (IntPtr sourceArray, Type destType)
558558
try {
559559
if (!IsAssignableFrom (lrefSource, grefDest)) {
560560
throw new InvalidCastException (FormattableString.Invariant (
561-
$"Unable to cast from '{Java.Interop.TypeManager.GetClassName (lrefSource)}' to '{Java.Interop.TypeManager.GetClassName (grefDest)}'."));
561+
$"Unable to cast from '{JniEnvironment.Types.GetJniTypeNameFromClass (new JniObjectReference (lrefSource))}' to '{JniEnvironment.Types.GetJniTypeNameFromClass (new JniObjectReference (grefDest))}'."));
562562
}
563563
} finally {
564564
DeleteGlobalRef (grefDest);
@@ -1167,7 +1167,7 @@ public static IntPtr NewObjectArray<T>(params T[]? values)
11671167
return IntPtr.Zero;
11681168

11691169
IntPtr grefArrayElementClass = GetArrayElementClass (values);
1170-
if (Java.Interop.TypeManager.GetClassName (grefArrayElementClass) == "mono/android/runtime/JavaObject") {
1170+
if (JniEnvironment.Types.GetJniTypeNameFromClass (new JniObjectReference (grefArrayElementClass)) == "mono/android/runtime/JavaObject") {
11711171
DeleteGlobalRef (grefArrayElementClass);
11721172
grefArrayElementClass = NewGlobalRef (Java.Lang.Class.Object);
11731173
}

0 commit comments

Comments
 (0)