Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding problem on same method on multiple interfaces #1177

Open
fedemkr opened this issue Jan 8, 2024 · 1 comment
Open

Binding problem on same method on multiple interfaces #1177

fedemkr opened this issue Jan 8, 2024 · 1 comment
Labels
generator Issues binding a Java library (generator, class-parse, etc.) question Item is a user question, and should not involve a coding change

Comments

@fedemkr
Copy link

fedemkr commented Jan 8, 2024

Problem

I'm trying to bind a library that has a dependency on this other library JNA (version 5.13.0) but when adding the JNA .jar file and set it as Bind=False on the csproj I'm getting one error regarding multiple interfaces having the same method, so basically it's like this:

public interface ToNativeConverter {
  Object toNative(Object paramObject, ToNativeContext paramToNativeContext);
  
  Class<?> nativeType();
}

public interface FromNativeConverter {
  Object fromNative(Object paramObject, FromNativeContext paramFromNativeContext);
  
  Class<?> nativeType();
}

public interface TypeConverter extends FromNativeConverter, ToNativeConverter {}

As you can see, both interfaces have Class<?> nativeType() and that's why the ITypeConverter fails when compiling the binding project:

The call is ambiguous between the following methods or properties: 'IFromNativeConverter.NativeType()' and 'IToNativeConverter.NativeType()'

On the generated code, it would be this:

static IntPtr n_NativeType (IntPtr jnienv, IntPtr native__this)
{
	var __this = global::Java.Lang.Object.GetObject<global::Com.Sun.Jna.ITypeConverter> (jnienv, native__this, JniHandleOwnership.DoNotTransfer)!;
	return JNIEnv.ToLocalJniHandle (__this.NativeType ()); // Here THE ERROR
}

Attempted non-working solutions

I attempted to create a new IBaseNativeConverter in C# binding project with that method and remove the nodes from the two aforementioned interfaces and then just let IFromNativeConverter and IToNativeConverter implement IBaseNativeConverter so we have the method in just one interface but then I get an error saying that the {From|To|Type}NativeConverterInvoker does not implement my C# Java.Lang.Class? NativeType() method.

Question

Should I implement a similar call like the above that was throwing an error on each ...Invoker?
Or what can I do to fix this without changing the library java source code?

Notes:

Here you have the Metadata.xml:

<attr path="/api/package[@name='com.sun.jna']/interface[@name='Callback']" name="name">ICallback</attr>
<remove-node path="/api/package[@name='com.sun.jna']/class[@name='JNIEnv']" />

And btw, I had to remove the node for JNIEnv since that's being used by the Xamarin binding generator and was causing some problems on binding the lib.
Also, I attempted to create a separate binding project for JNA only and ended up with the same errors.

@jpobst
Copy link
Contributor

jpobst commented Jan 8, 2024

Some ideas:

If you don't use the method nativeType(), you could try removing it from one or both of the interfaces.

If you aren't trying to consume or implement either interface, you could remove the whole interface types, or remove TypeConverter.

You could try renaming one of the methods with managedName to something like nativeType2().

@jpobst jpobst added question Item is a user question, and should not involve a coding change generator Issues binding a Java library (generator, class-parse, etc.) labels Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues binding a Java library (generator, class-parse, etc.) question Item is a user question, and should not involve a coding change
Projects
None yet
Development

No branches or pull requests

2 participants