Using simple .net4.6 DLL is so complicated

Hello,

I’m a bit confused, being a .net dev for long time and using Unity for last few years, and I still get stuck from time to time when using C# class libs with Unity.

For my current project, I’m trying to use an open source c# class lib, which I’ve used in another WinForms app successfully.

Link to library: GitHub - dotnet/MQTTnet: MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.

My project is targeted for Windows only, and I’d like to use this library. I’ve made a folder in Unity, Plugins/MQTTnet, and copied the files compiled dlls (for .net 4.6) from MQTTnet solution to this folder. I’ve set Unity Player settings to use 4.6 experimental for Scripting Runtime Version. It was not recognized with 3.5 selected.

Now, I can add “using MQTTnet” and init MQTTnet class instance, but when I put event handlers, I see error asking to add reference to System.Runtime.

Now here it gets confusing, I’ve .net 3.5, 4.5, 4.6, 4.7 all installed on this machine, I can add “using System.Runtime” but still there’s this error. Adding a reference is not available in VS2017, so how do I add reference to this missing System.Runtime?

I’m using Unity 2017.3 on Windows 10 Pro 64bit (16299.192).

Try finding the System.Runtime DLL on your PC and try to simply copy it into your assets folder.

1 Like

Thanks, I searched and found one in “C:\Windows\Microsoft.NET\Framework64\v4.0.30319” folder. Copied this one and System.Threading.Tasks.dll, and boom!

Connected to MQTT broker and received messages.

1 Like

Just an updated - I’ve tested this library in Unity 2018 beta with the updated runtime. Works pretty much out of the box.

I have a similar problem with one big difference: I can run the project on the simulator but I can’t attach VS to unity. VS says it can’t find MQTTnet types while it tries to compile

it seems that it’s VS 2017’s (2017.7.1) issue

Hi where did u guys find the dll package in the mqtt folder?

You don’t. On github you can create releases which you can access on the right side of the page when you scroll down a bit. When you load the source repository, you would need to compile it yourself.

ps: I just noticed that they don’t provide the actual compiled DLL in the releases. However they create a nuget packet. So you could load it through nuget, or download the nuget package manually and extract the version you want. The nuget package is also just a zip file.