SignalR 在 Unity3D WebGL 构建中给出错误

SignalR gives and Error with Unity3D WebGL Build

我在 Unity3D 编辑器和 Windows 独立构建中建立了一个 SignalR 连接,但是当我进行 WebGL 构建时,我在连接到集线器时遇到以下错误。

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

我无法找到关于为什么只在 WebGL 上发生这种情况的答案,我什至不确定是因为它是 WebGL 还是因为与 Unity 有关。

有没有其他人遇到过这个问题并且知道为什么它只出现在 WebGL 构建中。

编辑:添加来自异常的跟踪

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)

我可以调试 hubUrl 和 access_token 并在调试中打印出它们的值,所以我知道不是它们造成的。

好的,经过多次调试并试图解决这个问题,结果证明是线程问题(不是异常表明)。

由于 JavaScript 中缺少线程支持,Unity 不支持多线程,本质上,不支持 System.Threading 命名空间中的任何内容,但这是 SignalR 的要求。

Unity 表示他们计划添加多线程支持,但没有确定何时添加。

我会把它留在这里,以防其他人遇到这个问题。