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");

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

                if (jsonObj["newPlayer"] != "null")
                    Instantiate(OtherChar, SpawnPos, new Quaternion(0, 0, 0, 0));


        //If server connection closes (not client originated)
        socket.OnClose += (sender, e) =>
            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


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