Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

CS1503 changing string to JLO via managedType #967

Description

@jpobst

Context: dotnet/android-libraries#512

If you need to change a string to JLO for a method parameter, the generated code produces a CS1503 error because it generates this code:

// Metadata.xml XPath method reference: path="/api/package[@name='androidx.activity.result.contract']/class[@name='ActivityResultContracts.RequestPermission']/method[@name='createIntent' and count(parameter)=2 and parameter[1][@type='android.content.Context'] and parameter[2][@type='java.lang.String']]"[Register("createIntent","(Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;","")]publicoverrideunsafeglobal::Android.Content.IntentCreateIntent(global::Android.Content.Contextcontext,global::Java.Lang.Objectinput){conststring__id="createIntent.(Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;";IntPtrnative_input=JNIEnv.NewString(input);try{JniArgumentValue*__args=stackallocJniArgumentValue[2];__args[0]=newJniArgumentValue((context==null)?IntPtr.Zero:((global::Java.Lang.Object)context).Handle);__args[1]=newJniArgumentValue(native_input);var__rm=_members.InstanceMethods.InvokeAbstractObjectMethod(__id,this,__args);returnglobal::Java.Lang.Object.GetObject<global::Android.Content.Intent>(__rm.Handle,JniHandleOwnership.TransferLocalRef);}finally{JNIEnv.DeleteLocalRef(native_input);global::System.GC.KeepAlive(context);global::System.GC.KeepAlive(input);}}

This produces:

Error CS1503 Argument 1: cannot convert from 'Java.Lang.Object' to 'string?'

For this line:

IntPtrnative_input=JNIEnv.NewString(input);

Although there is a cast from JLO to string, the cast is explicit, meaning we need to use this:

IntPtrnative_input=JNIEnv.NewString((string?)input);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugComponent does not function as intendedgeneratorIssues binding a Java library (generator, class-parse, etc.)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions