Confluent-kafka-dotnet: ArgumentException in Unity3D (mono)

Created on 28 Nov 2018  路  5Comments  路  Source: confluentinc/confluent-kafka-dotnet

via community slack:

I'm trying to integrate a kafka client in a Unity3D project (based on mono).
When I try to initialize the Confluent .NET client I get an ArgumentException with "method return type is incompatible" message thrown from the CreateDelegate() in the Librdkafka.SetDelegates() method.
When I'm running my code in a .NET framework tester it runs with no problem, so I guess the mono framework used in Unity is causing the problem.

MEDIUM bug

Most helpful comment

@mhowlett Can you providea detail guide/tutorial for kafka and unity3d integration?

All 5 comments

Which version? if not 1.0-beta2, please try that version, there is a small chance this was fixed by something I did recently (but I don't think so).

I don't know exactly where the problem is without testing (note: I've never used the library with mono myself). I'm concerned this may indicate a problem in the interop code that is relevant to all frameworks - it may be that the only one that picks up on this is mono. for that reason we should look into this further.

Yes, the version I'm using is 1.0.0-beta2

I think the problem is related to this line in LibRdKafka.cs:
_event_type = (Func<IntPtr, EventType>)methods.Single(m => m.Name == "rd_kafka_event_type").CreateDelegate(typeof(Func<IntPtr, EventType>));

since the method type declared in NativaMethods.cs is:
[DllImport(DllName, CallingConvention =CallingConvention.Cdecl)]
internal static extern int rd_kafka_event_type(IntPtr rkev);

I changed the int to Librdkafka.EventType and it fixed this problem for me:
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern Librdkafka.EventType rd_kafka_event_type(IntPtr rkev);

thanks for investigating! yep, that'd do it. Will include in -beta3.

@mhowlett Can you providea detail guide/tutorial for kafka and unity3d integration?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreas-soroko picture andreas-soroko  路  3Comments

farodin91 picture farodin91  路  3Comments

keggster101020 picture keggster101020  路  4Comments

ietvijay picture ietvijay  路  3Comments

jeffreycruzana picture jeffreycruzana  路  3Comments