question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kafka in Unity not working. Seems to have broken assemblies or conflicting with Unity's. How to fix?

See original GitHub issue

Description

I want to integrate Kafka in Unity for a Windows build (I am on Windows).

However I either get errors such as this one:

Error: Could not load signature of Confluent.Kafka.IAsyncDeserializer`1[T]:DeserializeAsync due to: Could not load file or assembly 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. assembly:System.Memory, Version=4.0.1.0,

Or if I install the System.Memory version that comes with the Kafka NuGet dependency, I get errors all over the place of Unity’s own method/class references no longer being found.

How to reproduce

I have tried installing the latest release (1.3.0) from nuget (using the UnityPackage ‘NuGetForUnity’). This did not seem to work and had the second type of error result described above.

I have then tried to build the source and copy the relevant DLL’s manually, and tried the same with the nuget release version. This gives the first type of error result described above.

Can anyone please help me with installing Kafka for Unity?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
Mason-McGoughcommented, Dec 21, 2021

@ztolley I needed to do the same thing and recently figured it out. You may be missing the librdkafka.dll file for your system. For reference, here are the steps I used to get Kafka working in my project:

  1. Download and install the NuGet for Unity .unitypackage from their GitHub.
  2. In Unity, open “NuGet”->“Manage NuGet Packages” and install “Confluent.Kafka”.
  3. From the NuGet package page for librdkafka, click “Download Package”.
  4. Extract the archive. Under the “runtimes” folder, copy the folder for your system (I am on Ubuntu 18.04 so I picked “linux-x64”) and paste it under “Assets/Packages/Confluent.Kafka.<version>/lib/netstandard2.0” in Unity.
  5. Create a C# script called “KafkaConsumer” and paste the code @Phantomb provided.
  6. If needed, change BootstrapServers = "localhost:9092" to reflect your server and c.Subscribe("networktopic_data"); to the name of the topic you wish to subscribe to.
  7. You might need to modify a few more things to get it to work for your case. To get started, find and replace StreamMessage with string for now. Replace StreamMessage message = ParseStreamMessage.Decode(cr.Value); with string message = Encoding.UTF8.GetString(cr.Value);. Replace ProcessPBMessages.Process(message); with Debug.Log(message);. Once you can play the scene and confirm you are receiving messages in the Console, you can try using Newtonsoft JsonConvert or something similar to work for your use case.

Hope that helps!

3reactions
mhowlettcommented, Oct 7, 2022

reopening, it would be good for us to test this and make this work ootb.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conflict between Asset's Newtonsoft and ...
Hey guys, (Unity 2019.3.4f1) So i want to start my new project and i wanted to use Entities in it. I have already...
Read more >
Unable to use Confluent.Kafka with WebGL in Unity #1967
Description When building a Unity application that has the Confluent.Kafka .NET library into a WebGL build, the following errors are ...
Read more >
Trying to implement Kafka in Unity, has anyone managed ...
Trying to implement Kafka in Unity, has anyone managed to get it working? I have issues with library / assembly versions conflicting.
Read more >
Fixing the missing assembly reference error in Unity projects
Solution to the problem. The solution is actually surprisingly simple, provided you know what assemblies are and how the fit into a project....
Read more >
Kafka integration in unity3d throwing Win32Exception error
Kafka dll into my project asset folder. but whenever I run my unity game it throws an error:Win32Exception: The specified module could not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found