You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed we're invoking the wrong constructors in the generated IL, for example:
// ILSpy output:// _TypeMap.Proxies.Android_Runtime_JavaProxyThrowable_ProxyusingSystem;usingSystem.Runtime.CompilerServices;usingSystem.Runtime.InteropServices;usingAndroid.Runtime;usingJava.Interop;usingJava.Lang;[UnmanagedCallersOnly]publicstaticvoidnctor_1_uco(System.IntPtrP_0,System.IntPtrP_1,System.IntPtrP_2,System.IntPtrP_3,byteP_4,byteP_5){//IL_0029: Unknown result type (might be due to invalid IL or missing references)JniTransitionval=default(JniTransition);JniRuntimeval2=default(JniRuntime);if(!JniEnvironment.BeginMarshalMethod(P_0,refval,refval2)){return;}try{if(!JavaPeerProxy.ShouldSkipActivation(P_1)){// we are not resolving P_1, P_2, P_3!((Error)(JavaProxyThrowable)RuntimeHelpers.GetUninitializedObject(typeof(JavaProxyThrowable)))..ctor(P_1,(JniHandleOwnership)0);// we are calling the wrong constructor! we should be calling the one with the 5 parameters here!}}catch(System.Exceptionex){if(val2!=null){val2.OnUserUnhandledException(refval,ex);}}finally{JniEnvironment.EndMarshalMethod(refval);}}
The current trimmable typemap code no longer blindly calls the (IntPtr, JniHandleOwnership) activation constructor when a matching managed constructor exists. It now tracks HasMatchingManagedCtor / ManagedParameterTypes, emits RuntimeHelpers.GetUninitializedObject, sets the activation peer reference, marshals JNI constructor arguments, and calls the user-visible managed constructor.
Object-reference constructor parameters are marshalled through Java.Lang.Object.GetObject, which addresses the original issue's example where constructor arguments were not resolved before invoking the managed constructor.
Regression coverage exists for this behavior, including:
Activity
simonrozsival commentedon May 25, 2026
This appears to be fixed in
mainnow.Evidence:
origin/main:[TrimmableTypeMap] Fix UCO constructor activation— the direct fix for generated UCO constructor activation.(IntPtr, JniHandleOwnership)activation constructor when a matching managed constructor exists. It now tracksHasMatchingManagedCtor/ManagedParameterTypes, emitsRuntimeHelpers.GetUninitializedObject, sets the activation peer reference, marshals JNI constructor arguments, and calls the user-visible managed constructor.Java.Lang.Object.GetObject, which addresses the original issue's example where constructor arguments were not resolved before invoking the managed constructor.ActivatedDirectThrowableSubclasses_ThrowableCtor_ShouldForwardArgsActivatedDirectThrowableSubclasses_MultipleCtors_ShouldDispatchToCorrectCtorGetObjectand invoke the user-visible constructor.Closing as fixed by the merged constructor-activation work, primarily #11275 and #11123, with #11461 as a related follow-up.