Hello community!
I'm using SignalR to send event notifications like when a player sends a friend request to another player or sends a Battle Request and everything works fine on the Unity Editor but when I make a build for iOS I get an error.
This is the code I'm using to initialize the SignalR Hub Connection
public void BuildHubConnector() {
string url = "verified_url_in_web_app_azure_services";
var hubConnectionBuilder = new HubConnectionBuilder();
hubConnectionBuilder.WithUrl(url);
hubConnection = hubConnectionBuilder.Build();
}
But when I try to run it on iOS, this error message appears.
InvalidOperationException: Sequence contains no matching element
System.Linq.Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) (at <00000000000000000000000000000000>:0)
Microsoft.AspNetCore.SignalR.Client.HubConnection..cctor () (at <00000000000000000000000000000000>:0)
System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor (System.Type serviceType) (at <00000000000000000000000000000000>:0)
System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService (System.IServiceProvider provider, System.Type serviceType) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T] (System.IServiceProvider provider) (at <00000000000000000000000000000000>:0)
SignalRPersistentConnection.Update () (at <00000000000000000000000000000000>:0)
Rethrow as TypeInitializationException: The type initializer for 'Microsoft.AspNetCore.SignalR.Client.HubConnection' threw an exception.
System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor (System.Type serviceType) (at <00000000000000000000000000000000>:0)
System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService (System.IServiceProvider provider, System.Type serviceType) (at <00000000000000000000000000000000>:0)
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T] (System.IServiceProvider provider) (at <00000000000000000000000000000000>:0)
SignalRPersistentConnection.Update () (at <00000000000000000000000000000000>:0)
The steps that I'm following to use SignalR with unity are these: 1. Create a dotnet project with the Microsoft.AspNetCore.SignalR.Client library. (I've tried many versions) 2. Publish the project using "dotnet publish -c Release -r win-x64 --self-contained true". 3. Copy the Dlls to a Plugins folder located inside the Assets folder in the unity project. 4. Make the iOS build with unity and then make the build and run in XCode directly on my iphone.
That's it, everything works until this line of code "hubConnection = hubConnectionBuilder.Build();"
I don't understand why this happens only on iOS and not on Unity Editor, supposedly it is using a .Net framework compatible with both systems.
I'll appreciate any comments, thoughts, and of course, solutions. Thanks!