socket.io-client-csharp
socket.io-client-csharp copied to clipboard
MissingMethodException: Constructor on type 'System.Text.Json.Serialization.Converters.ArrayConverter
SocketIO client = new SocketIO("url");
client.ConnectAsync();
private async send(){ await client.EmitAsync("test", "message"); }
this code is worked on Unity Editor bur didn't working android platform with this error sorry, i'm not good at english
.net 4.x
Exception
MissingMethodException: Constructor on type 'System.Text.Json.Serialization.Converters.ArrayConverter2[[System.Object[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' not found. System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) (at <00000000000000000000000000000000>:0) System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) (at <00000000000000000000000000000000>:0) System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture) (at <00000000000000000000000000000000>:0) System.Text.Json.Serialization.Converters.IEnumerableConverterFactory.CreateConverter (System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) (at <00000000000000000000000000000000>:0) System.Text.Json.Serialization.JsonConverterFactory.GetConverterInternal (System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonSerializerOptions.GetConverter (System.Type typeToConvert) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonSerializerOptions.DetermineConverter (System.Type parentClassType, System.Type runtimePropertyType, System.Reflection.MemberInfo memberInfo) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonClassInfo.GetConverter (System.Type type, System.Type parentClassType, System.Reflection.MemberInfo memberInfo, System.Type& runtimeType, System.Text.Json.JsonSerializerOptions options) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonClassInfo..ctor (System.Type type, System.Text.Json.JsonSerializerOptions options) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonSerializerOptions.GetOrAddClass (System.Type type) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonSerializerOptions.GetOrAddClassForRootType (System.Type type) (at <00000000000000000000000000000000>:0) System.Text.Json.WriteStack.Initialize (System.Type type, System.Text.Json.JsonSerializerOptions options, System.Boolean supportContinuation) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonSerializer.WriteCore[TValue] (System.Text.Json.Utf8JsonWriter writer, TValue& value, System.Type inputType, System.Text.Json.JsonSerializerOptions options) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonSerializer.Serialize[TValue] (TValue& value, System.Type inputType, System.Text.Json.JsonSerializerOptions options) (at <00000000000000000000000000000000>:0) System.Text.Json.JsonSerializer.Serialize[TValue] (TValue value, System.Text.Json.JsonSerializerOptions options) (at <00000000000000000000000000000000>:0) SocketIOClient.JsonSerializer.SystemTextJsonSerializer.Serialize (System.Object[] data) (at <00000000000000000000000000000000>:0) SocketIOClient.SocketIO.GetDataString (System.Object[] data) (at <00000000000000000000000000000000>:0) SocketIOClient.SocketIO+<EmitAsync>d__99.MoveNext () (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) (at <00000000000000000000000000000000>:0) SocketIOClient.SocketIO.EmitAsync (System.String eventName, System.Threading.CancellationToken cancellationToken, System.Object[] data) (at <00000000000000000000000000000000>:0) SocketIOClient.SocketIO+<EmitAsync>d__98.MoveNext () (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) (at <00000000000000000000000000000000>:0) SocketIOClient.SocketIO.EmitAsync (System.String eventName, System.Object[] data) (at <00000000000000000000000000000000>:0) SocketIOTest+<DB>d__4.MoveNext () (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) (at <00000000000000000000000000000000>:0) SocketIOTest.DB () (at <00000000000000000000000000000000>:0) UnityEngine.Events.UnityAction.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.Events.InvokableCall.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.Events.UnityEvent.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.UI.Button.Press () (at <00000000000000000000000000000000>:0) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.ExecuteEvents+EventFunction1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction1[T1] functor) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean pressed, System.Boolean released) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.Process () (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.EventSystem.Update () (at <00000000000000000000000000000000>:0) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.TaskAwaiter.GetResult () (at <00000000000000000000000000000000>:0) SocketIOClient.SocketIO+<EmitAsync>d__98.MoveNext () (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) (at <00000000000000000000000000000000>:0) SocketIOClient.SocketIO.EmitAsync (System.String eventName, System.Object[] data) (at <00000000000000000000000000000000>:0) SocketIOTest+<DB>d__4.MoveNext () (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) (at <00000000000000000000000000000000>:0) SocketIOTest.DB () (at <00000000000000000000000000000000>:0) UnityEngine.Events.UnityAction.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.Events.InvokableCall.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.Events.UnityEvent.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.UI.Button.Press () (at <00000000000000000000000000000000>:0) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.ExecuteEvents+EventFunction1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction1[T1] functor) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean pressed, System.Boolean released) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.Process () (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.EventSystem.Update () (at <00000000000000000000000000000000>:0) --- End of stack trace from previous location where exception was thrown --- System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.TaskAwaiter.GetResult () (at <00000000000000000000000000000000>:0) SocketIOTest+<DB>d__4.MoveNext () (at <00000000000000000000000000000000>:0) System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) (at <00000000000000000000000000000000>:0) SocketIOTest.DB () (at <00000000000000000000000000000000>:0) UnityEngine.Events.UnityAction.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.Events.InvokableCall.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.Events.UnityEvent.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.UI.Button.Press () (at <00000000000000000000000000000000>:0) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.ExecuteEvents+EventFunction1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at <00000000000000000000000000000000>:0)
UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean pressed, System.Boolean released) (at <00000000000000000000000000000000>:0)
UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () (at <00000000000000000000000000000000>:0)
UnityEngine.EventSystems.StandaloneInputModule.Process () (at <00000000000000000000000000000000>:0)
UnityEngine.EventSystems.EventSystem.Update () (at <00000000000000000000000000000000>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <00000000000000000000000000000000>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <00000000000000000000000000000000>:0)
System.Threading.SendOrPostCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()
Can you create a reproducible demo?
// https://forum.unity.com/threads/please-add-system-text-json-support.1000369/ // System.Text.Json won't work in current il2cpp.
// use Newtonsoft Json.Net as a serializer to avoid unity/system-text-json issues : client.JsonSerializer = new NewtonsoftJsonSerializer();
when data received, parse it like this:
socketIOResponse.GetValue<string>(); // for a primitive type (string, int, float ...)
/*
else if it's an object, you can use the default unity serializer
(or: https://github.com/jilleJr/Newtonsoft.Json-for-Unity
via client.JsonSerializer = new NewtonsoftJsonSerializer()
and socketIOResponse.GetValue<CustomClass>()
) :
*/
// using default unity serializer :
JsonUtility.FromJson<T>(socketIOResponse.GetValue(0).GetRawText());
// example:
client.On("eventName", (res) =>
{
Debug.Log("eventName ");
Debug.Log("raw text: " + res.GetValue(0).GetRawText());
CustomClass object = JsonUtility.FromJson<CustomClass>(res.GetValue(0).GetRawText());
Debug.Log("CustomClass: "+object.ToString());
// ...
});