InvalidCastException: Specified cast is not valid. (NETWORKING)

I am making a multiplayer FPS game and I am getting the error in the title.

Here is the whole error:

InvalidCastException: Specified cast is not valid.
GameManager.UpdatePlayers_R(System.Object data) (which is the script and function down below)

public void UpdatePlayers_R(object[] data)
        playerInfo = new List<PlayerInfo>();

        for (int i = 0; i < data.Length; i++)
            object[] extract = (object[])data*;*

PlayerInfo p = new PlayerInfo // marks the error here
new ProfileData
(int) extract[1],
(int) extract[2]
(int) extract[3],
(short) extract[4],
(short) extract[5]


if (PhotonNetwork.LocalPlayer.ActorNumber == myind = i - 1;

Well it’s pretty obvious that at least one of the values in your nested “extract” array is not what you think it is. So either the first element is not a string, element 1,2 or 3 is not an int or element 4 or 5 is not a short. Since you used an object initializer we can not tell you which one it might be. You could try splitting the casts into seperate lines with local variables in order to figure out which one it is:

var p0 = (string)extract[0];
var p1 = (int) extract[1];
var p2 = (int) extract[2];
var p3 = (int) extract[3];
var p4 = (short) extract[4];
var p5 = (short) extract[5];

PlayerInfo p = new PlayerInfo
    new ProfileData ( p0, p1,p2 ),

Now it should point you to the exact line where the cast fails. Once you know which element it is you can print its actual type. Just place this loop before you do any casting and it will print the types of all values.

for(int i = 0; i extract.Length; i++)
    if (extract *== null)*

Debug.Log(“extract[”+i+“] is null”);
Debug.Log(“extract[”+i+"] type == " + extract*.GetType().Name);*