java.lang.IllegalArgumentException when registering a callback

In a .NET-to-Java project, when code executes that registers a callback/listener with the Java side, you might see a java.lang.IllegalArgumentException. If this happens, it is because your [Callback] or [AsyncCallback] attribute names a listener interface that differs from the one that the Java-side code actually expects.

For example, if you have proxied the Java method:

public void registerListener(MyListenerInterface)

and have implemented .NET code like the following:

[Callback(“java.util.EventListener”)]
public class MyListenerClass : MyListenerInterface { … }

and then call:

javaClass.registerListener(new MyListenerClass());

the code will properly compile, but when it executes, an IllegalArgumentException will be thrown.

If this happens, the solution is to make sure that the [Callback] or [AsyncCallback] attribute specifies the precise listener class expected on the Java side.  In this case, changing the attribute to

[Callback(“MyListenerInterface”)]

will solve the problem.  Note that the attribute must contain the fully qualified name of the interface.