MulticastDelegate for asynchronous callback from Java to DotNet

415 views
Skip to first unread message

Shawn Garner

unread,
Jul 11, 2013, 11:17:27 AM7/11/13
to jni...@googlegroups.com
Hello,

We have a third party dll which we were trying to call from Java.
We ran into an issue with trying to do an asynchronous callback.

The C# method signature is:
public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
and ConnectionStateChangedEventArgs extends  EventArgs

When I generate the proxy to my class with the above method signature I get a Java method which has the following signature:
@net.sf.jni4net.attributes.ClrMethod("([[LSystem/EventHandler`1;)V")
    public native void addConnectionStateChanged(system.MulticastDelegate value);

I'm trying to add a MulticastDelegate and having difficulty.

I looked at an example from your a previous posting and tried to use:
new system.EventHandler(){
 Invoke(...) {do something}
}

and also 
new system.AsyncCallback() {
 Invoke(...) { do something }
}

In both cases we get this:
Exception in thread "main" System.ArgumentNullException: Value cannot be null.
Parameter name: method
   at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
   at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
   at net.sf.jni4net.utils.Convertor.StrongJ2CpDelegate[TRes](JNIEnv env, JniLocalHandle obj)
   ...

I saw in a previous posting that you recommended creating a C# wrapper.
We are trying to use jni4net because our companies only does development in Java.
We don't wish to have separate skill-sets, tooling, pipelines, etc for C#  so making this work without a C# wrapper would be highly preferable.

Shawn

Shawn Garner

unread,
Jul 17, 2013, 9:44:34 AM7/17/13
to jni...@googlegroups.com
Hello,

I haven't heard back from anyone so I'm re-posting.

I was just wondering if anyone had an ideas of what the issue is here and if there is some kind of work around to this issue other than creating a C# wrapper?  We are evaluating different options of integrating Java with a DotNet library and this MulticastDelegate callback issue is something that'd make us not choose jni4net.  Assuming this is an un-implemented feature we might get my company to dedicate some hours to a fix/enhancement.  We've contributed to other OSS projects in the past.

Shawn

Pavel Šavara

unread,
Jul 17, 2013, 10:35:09 AM7/17/13
to jni...@googlegroups.com
In general, you will need to understand both environments you are trying to integrate, so your comment about C# skillset  ....

I'm not sure what is wrong in your case. 
Here is event sample which should work




--
--
You received this message because you are subscribed to jni...@googlegroups.com
http://groups.google.com/group/jni4net?hl=en-GB?hl=en-GB
http://jni4net.sf.net/
 
---
You received this message because you are subscribed to the Google Groups "jni4net" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jni4net+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Shawn Garner

unread,
Jul 17, 2013, 11:05:28 AM7/17/13
to jni...@googlegroups.com
We tried tried new system.EventHandler() {...} like in the TestForm.java but get the same error.
I think it may be because our EventHandler uses generics for the event args and is not just a simple plain EventHandler, 
eg:
public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged

Does jni4net support event handlers with generics?

Shawn

Pavel Šavara

unread,
Jul 18, 2013, 2:27:05 AM7/18/13
to jni...@googlegroups.com
jni4net doesn't support generics
Reply all
Reply to author
Forward
0 new messages