InvalidProgramException: Invalid IL code

InvalidProgramException: Invalid IL code in MyNetworkPlayer:SetDisplayName (string): IL_000f: call      0x0a00000a

This error pops up every time I try to Host(Server + Client) from the unity editor, and my name isn’t being set. Up until this point everything was working properly. The error points to the line in MyNetworkManager where I’m calling SetDisplayName on the player. I’m using the current release of mirror, 30.5.0. Below is the code:

using UnityEngine;
using Mirror;

public class MyNetworkManager : NetworkManager
{
    public override void OnServerAddPlayer(NetworkConnection conn)
    {
        base.OnServerAddPlayer(conn);

        MyNetworkPlayer player = conn.identity.GetComponent<MyNetworkPlayer>();
        player.SetDisplayName($"Player {numPlayers}");
    }
}
using UnityEngine;
using Mirror;

public class MyNetworkPlayer : NetworkBehaviour
{
    [SyncVar]
    [SerializeField]
    private string displayName = "Missing Name";

    [Server]
    public void SetDisplayName(string newDisplayName)
    {
        displayName = newDisplayName;
    }
}

Since this is an example project I’ll just keep going on with the course ignoring it for now, but I’m scared this problem might persist later on. Could this be a problem with the package version/unity version?

1 Like

Alright for anyone else experiencing this problem: it appears to be a bug with Mirror, since the same issue is open on their forums. A quick fix is removing the [Server] attribute above the SetDisplayName function. I don’t like the idea of using something buggy, but it will do for now.

2 Likes

Hi, I have been encouraging people not to use Unity 2020.2 with Mirror for this course, since it creates this issue as well. Which version of Unity are you using? Do you have a link to the Mirror forum for this, I would be interested to see. Glad you found an easy fix.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms