WebSocketSharp event not spawning sprite

I am making a multiplayer game with WebSocketSharp.
And when another player joins the server I want to spawn a sprite that represents the other player.
But the code that spawns the sprite stops right at the Instantiate function.
In console i see the “1” and nothing after that .

private IEnumerator Connect()
    {
        socket = new WebSocket("ws://localhost:8080");
        socket.Connect();

        //WebSocket onMessage function
        socket.OnMessage += (sender, e) =>
        {
            //If received data is type text...
            if (e.IsText)
            {
                Debug.Log(e.Data);
                JSONNode jsonObj = JSON.Parse(e.Data);
                Debug.Log("OtherPlayer = " + jsonObj["newPlayer"]);

                if (jsonObj["newPlayer"] != "null")
                {
                    Debug.Log("1");
                    Instantiate(OtherChar, SpawnPos, new Quaternion(0, 0, 0, 0));
                    Debug.Log("2");
                }
            }

            
        };

        //If server connection closes (not client originated)
        socket.OnClose += (sender, e) =>
        {
            Debug.Log(e.Code);
            Debug.Log(e.Reason);
            Debug.Log("Connection Closed!");
        };

        yield break;
    }

the only way code doesnt executes is because Instantiate method crashes and returns an error, simply read the error

also, that quaternion doesnt exist, change to

Quaternion.identity

I found this and it fixed the problem.
It was because websocketsharp runs on another thread.