- Home /
Using SignalR client in Android/iOS app
I'm trying to use my mobile application (for Android and iOS) as a SignalR client built with Unity3d version 2019.2.9f1 (I have also tried with 2019.4.0f1 with no difference).
I began by downloading the latest version of the AspNetCore SignalR client from nuget and extracting the dll. I placed this in my Plugins folder, and repeated the process for each of its dependencies, getting the latest version of each from nuget.
I included a link.xml file to preserve each of the assemblies in that same folder:
<linker>
<assembly fullname="Microsoft.AspNetCore.Connections.Abstractions" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.Http.Connections.Client" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.Http.Connections.Common" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.Http.Features" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Client.Core" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Client" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Common" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Protocols.Json" preserve="all"/>
<assembly fullname="Microsoft.Extensions.DependencyInjection.Abstractions" preserve="all"/>
<assembly fullname="Microsoft.Extensions.DependencyInjection" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Logging.Abstractions" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Logging" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Options" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Primitives" preserve="all"/>
<assembly fullname="System.Buffers" preserve="all"/>
<assembly fullname="System.ComponentModel.Annotations" preserve="all"/>
<assembly fullname="Microsoft.Bcl.AsyncInterfaces" preserve="all"/>
<assembly fullname="System.Diagnostics.DiagnosticSource" preserve="all"/>
<assembly fullname="System.IO.Pipelines" preserve="all"/>
<assembly fullname="System.Memory" preserve="all"/>
<assembly fullname="System.Text.Encodings.Web" preserve="all"/>
<assembly fullname="System.Runtime.CompilerServices.Unsafe" preserve="all"/>
<assembly fullname="System.Text.Json" preserve="all"/>
<assembly fullname="System.Threading.Channels" preserve="all"/>
<assembly fullname="System.Threading.Tasks.Extensions" preserve="all"/>
</linker>
And my client code:
using Microsoft.AspNetCore.SignalR.Client;
using System;
using UnityEngine;
public class SignalRManager : MonoBehaviour
{
public static HubConnection myConnection;
public void StartSignalConnection()
{
try
{
Debug.Log("Before building");
myConnection = new HubConnectionBuilder().WithUrl("ServerURL").Build();
Debug.Log("After building");
myConnection.On<string>("MessageClient", message =>
{
Debug.Log("From signalR: " + message);
});
myConnection.StartAsync();
}
catch (Exception ex) { Debug.Log("My error caught here: " + ex.ToString()); }
}
public void SendMessage()
{
if (myConnection.State != HubConnectionState.Connected) { Debug.Log("Not connected yet"); return; }
myConnection.InvokeAsync("MessageClient", "Test message");
}
}
In the editor, all of the above works perfectly. I press a button in my scene and it starts the connection, and I press another button and a message is sent. Once I build to my Android device and try to start the connection, I get the following when I reach the .build() statement:
2020/11/11 10:13:46.980 20848 28520 Warn Unity Plugins: Couldn't open advapi32, error: dlopen failed: library "advapi32" not found
2020/11/11 10:13:46.980 20848 28520 Warn Unity Microsoft.Win32.ManifestEtw:EventRegister(Guid&, EtwEnableCallback, Void*, Int64&)
2020/11/11 10:13:46.980 20848 28520 Warn Unity System.Diagnostics.Tracing.EventProvider:Register(Guid)
2020/11/11 10:13:46.980 20848 28520 Warn Unity System.Diagnostics.Tracing.EventSource:Initialize(Guid, String, String[])
2020/11/11 10:13:46.980 20848 28520 Warn Unity Microsoft.Extensions.DependencyInjection.DependencyInjectionEventSource:.cctor()
2020/11/11 10:13:46.980 20848 28520 Warn Unity Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine:CreateServiceAccessor(Type)
2020/11/11 10:13:46.980 20848 28520 Warn Unity System.Func`2:Invoke(T)
2020/11/11 10:13:46.980 20848 28520 Warn Unity System.Collections.Concurrent.ConcurrentDictionary`2:GetOrAdd(TKey, Func`2)
2020/11/11 10:13:46.980 20848 28520 Warn Unity Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine:GetService(Type, ServiceProviderEngineScope)
2020/11/11 10:13:46.980 20848 28520 Warn Unity Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions:GetService(IServiceProvider)
2020/11/11 10:13:46.980 20848 28520 Warn Unity Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder:Build()
2020/11/11 10:13:46.980 20848 28520 Warn Unity SignalR:StartSignalRConnection()
2020/11/11 10:13:46.980 20848 28520 Warn Unity UnityEngine.Events.UnityAction:Invoke()
2020/11/11 10:13:46.980 20848 28520 Warn Unity UnityEngine.Events.UnityEvent:Invoke()
2020/11/11 10:13:46.980 20848 28520 Warn Unity UnityEngine.EventSystems.EventFunction
2020/11/11 10:13:47.027 20848 28520 Warn Unity Plugins: Couldn't open advapi32, error: dlopen failed: library "advapi32" not found
2020/11/11 10:13:47.027 20848 28520 Warn Unity Microsoft.Win32.ManifestEtw:EventRegister(Guid&, EtwEnableCallback, Void*, Int64&)
2020/11/11 10:13:47.027 20848 28520 Warn Unity System.Diagnostics.Tracing.EventProvider:Register(Guid)
2020/11/11 10:13:47.027 20848 28520 Warn Unity System.Diagnostics.Tracing.EventSource:Initialize(Guid, String, String[])
2020/11/11 10:13:47.027 20848 28520 Warn Unity System.Buffers.ArrayPoolEventSource:.cctor()
2020/11/11 10:13:47.027 20848 28520 Warn Unity System.Buffers.DefaultArrayPool`1:Rent(Int32)
2020/11/11 10:13:47.027 20848 28520 Warn Unity System.Text.Json.JsonEncodedText:TranscodeAndEncode(ReadOnlySpan`1, JavaScriptEncoder)
2020/11/11 10:13:47.027 20848 28520 Warn Unity System.Text.Json.JsonEncodedText:Encode(ReadOnlySpan`1, JavaScriptEncoder)
2020/11/11 10:13:47.027 20848 28520 Warn Unity System.Text.Json.JsonEncodedText:Encode(String, JavaScriptEncoder)
2020/11/11 10:13:47.027 20848 28520 Warn Unity Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol:.cctor()
2020/11/11 10:13:47.027 20848 28520 Warn Unity System.Reflection.MonoCMethod:InternalInvoke(Object, Object[])
2020/11/11 10:13:47.027 20848 28520 Warn Unity Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver:VisitConstructor(ConstructorCallSite, RuntimeResolverContext)
2020/11/11 10:13:47.027 20848 28520 Warn Unity Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver:VisitCache(ServiceCallSite, RuntimeResolverContext, ServiceP
2020/11/11 10:13:47.471 20848 28520 Warn Unity Plugins: Couldn't open advapi32, error: dlopen failed: library "advapi32" not found
2020/11/11 10:13:47.471 20848 28520 Warn Unity Microsoft.Win32.ManifestEtw:EventRegister(Guid&, EtwEnableCallback, Void*, Int64&)
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Diagnostics.Tracing.EventProvider:Register(Guid)
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Diagnostics.Tracing.EventSource:Initialize(Guid, String, String[])
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Net.NetEventSource:.cctor()
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Net.WebSockets.ClientWebSocket:.ctor()
2020/11/11 10:13:47.471 20848 28520 Warn Unity Microsoft.AspNetCore.Http.Connections.Client.HttpConnection:IsWebSocketsSupported()
2020/11/11 10:13:47.471 20848 28520 Warn Unity Microsoft.AspNetCore.Http.Connections.Client.Log:ErrorWithNegotiation(ILogger, Uri, Exception)
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Threading.ContextCallback:Invoke(Object)
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Runtime.CompilerServices.MoveNextRunner:Run()
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Action:Invoke()
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Threading.ContextCallback:Invoke(Object)
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Threading.Tasks.AwaitTaskContinuation:RunCallback(ContextCallback, Object, Task&)
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Threading.Tasks.Task:FinishContinuations()
2020/11/11 10:13:47.471 20848 28520 Warn Unity System.Threading.Tasks.Task`1:TrySetResult(TResult)
2020/11/11 10:13:47.471 20848 28520 Warn Unity Syste
I can see why the error is happening, but I'm not sure how to get around it. I believe the Libraries are using advapi32 to access some data from the registry (possibly the date and time for use in logging from what I've seen when researching this issue).
I tried adding in the dll and including it in my link.xml, but there was no change in behavior. My project is currently set to use an IL2CPP scripting backend with .NET 4.x compatibility.
Answer by boulos77 · Nov 18, 2020 at 08:21 PM
I ended up using the Best HTTP/2 asset from the Asset store. This allowed use of SignalR in the way I wanted without any compatibility issues.
Your answer
Follow this Question
Related Questions
[C#] guitexture as button for player move on iOS/android 1 Answer
Is it possible to send SMS from an action in Unity? (Mobile iOS or Android) 1 Answer
Can Unity support Video Ads through ad providers like Greystripe, Admob, etc? 1 Answer
iOS / Android OnApplicationPause: incoming calls vs home button 1 Answer
Native list views on Mobile? 0 Answers