I have got a SignalR connection working in the Unity3D Editor and Windows Standalone Build but when I do a WebGL build I get the following error when connecting to the Hub.

ArgumentNullException: Value cannot be null. Parameter name: format at System.String.FormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args)

I haven't been able to find an answer as to why this is happening only with WebGL and I am not even sure if it is because it is WebGL or because of something to do with Unity.

Has anyone else come across this and know why it is only being thrown on the WebGL build.

Edit: Adding trace of from the exception

ArgumentNullException: Value cannot be null. Parameter name: format 
at System.String.FormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args) [0x00000] in <00000000000000000000000000000000>:0 
at System.String.Format (System.IFormatProvider provider, System.String format, System.Object arg0) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.Resources.FormatNoConstructorMatch (System.Object p0) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite (System.Type serviceType, System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact (Microsoft.Extensions.DependencyInjection.ServiceDescriptor descriptor, System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor (System.Type serviceType) [0x00000] in <00000000000000000000000000000000>:0 
at System.Func`2[T,TResult].Invoke (T arg) [0x00000] in <00000000000000000000000000000000>:0 
at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T] (System.IServiceProvider provider) [0x00000] in <00000000000000000000000000000000>:0 
at Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder.Build () [0x00000] in <00000000000000000000000000000000>:0 
at PlayerConnection..ctor (System.String hubUrl, System.String access_token) [0x00000] in <00000000000000000000000000000000>:0 
at ConnectionManager.Init (System.String access_token) [0x00000] in <00000000000000000000000000000000>:0 
at SetupManager+<ConnectToHubs>d__5.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 
at UnityEngine.MonoBehaviour.StartCoroutineManaged2 (System.Collections.IEnumerator enumerator) [0x00000] in <00000000000000000000000000000000>:0 
at UnityEngine.MonoBehaviour.StartCoroutine (System.Collections.IEnumerator routine) [0x00000] in <00000000000000000000000000000000>:0 
at SetupManager+<WaitForAccessToken>d__4.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) <WaitForAccessToken>d__4:MoveNext() UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) 

(Filename: currently not available on il2cpp Line: -1)

I can debug both the hubUrl and access_token and print out in the debug their values so I know it isn't them causing it.

1 Answers

0
akaBase On Best Solutions

Okay, after much debugging and trying to figure this out it turns out to be an issue with threading (not that the exception indicates that).

Unity dosen't support multi-threading due to the lack of threading support in JavaScript, Essentially, anything in the System.Threading namespace is not supported but it is a requirement of SignalR.

Unity say they are planning to add multi-threading support but no time frame for when it will be added.

I will leave this here incase anyone else runs into this issue.