How to use SignalR in Unity3d?

Viewed 11020

I have a reason to use SignalR in Unity, I have decided to go with Microsoft.AspNetCore.SignalR.Client from NuGet.

I've tried a package Nivot.SignalR.Client.Net35 but it uses AspNet.SignalR.Client which is not used anymore, I have created everything I need on my WebApi solution using Microsoft.AspNetCore.SignalR, then I have changed in my Unity project in PlayerSettings Scripting Tuntime Version .NET 4.x Equivalent and Api Compatibility Level to .NET Standard 2.0, which is compatible with AspNetCore.SignalR.Client.

But after I install the package in visual studio while editing scripts and I try to use it Visual Studio keeps calm, but Unity says That the namespace Microsoft.AspNetCore.SignalR.Client doesn't exists. I have read that I have to copy them to a folder in the Assets folder, so I did it, and then Unity said "Unloading broken assembly Assets/Packages/Microsoft.AspNetCore.SignalR.Client.dll, this assembly can cause crashes in the runtime" and it doesn't work.

I've lost my hope. But then I remembered that there is Stackoverflow, so now I hope that someone here can help me. Thanks.

2 Answers

You'll have to target .net framework instead of .Net Standard 2.0 in your Unity project because there is no signalr Core out there that targets .Net Standard 2.0 that Unity does. Until Unity updates to 2.2 or 3.0, we're out of luck getting the client side SignalR Core lib working with Unity.

Alternatively, you could try to use a different .net websocket implementation on the client side in Unity.

Your error is related to missing dependencies.

Using the latest stable binaries, SignalR client and server both work in Unity3D. You can find the minimum set of DLLs you need here, in the AspNetCore and AspNetCoreClient1.1.0 directories. Include the associated .meta files. Visit this project's settings for proper configuration.

You cannot use nuget in Unity3D correctly, it is too buggy.

Related