Unity-Technologies/UnityCsReference · error · ArgumentException

Cant be Guid.Empty

Error message

Cant be Guid.Empty

What it means

Thrown by EditorConnection.Register when the messageId Guid equals Guid.Empty. Empty GUIDs are rejected because the native subscription layer needs a well-formed message identifier.

Source

Thrown at Editor/Mono/Networking/PlayerConnection/EditorConnection.cs:107

        private void UnregisterAllPersistedListeners(UnityEventBase connectionEvent)
        {
            var persistentEventCount = connectionEvent.GetPersistentEventCount();
            for (int i = 0; i < persistentEventCount; i++)
            {
                connectionEvent.UnregisterPersistentListener(i);
            }
        }

        private IPlayerEditorConnectionNative GetEditorConnectionNativeApi()
        {
            return connectionNative ?? new EditorConnectionInternal();
        }

        public void Register(Guid messageId, UnityAction<MessageEventArgs> callback)
        {
            if (messageId == Guid.Empty)
            {
                throw new ArgumentException("Cant be Guid.Empty", "messageId");
            }

            if (!m_PlayerEditorConnectionEvents.messageTypeSubscribers.Exists(x => x.MessageTypeId == messageId))
            {
                GetEditorConnectionNativeApi().RegisterInternal(messageId);
            }

            m_PlayerEditorConnectionEvents.AddAndCreate(messageId)
                .AddPersistentListener(callback, UnityEventCallState.EditorAndRuntime);
        }

        public void Unregister(Guid messageId, UnityAction<MessageEventArgs> callback)
        {
            m_PlayerEditorConnectionEvents.UnregisterManagedCallback(messageId, callback);
            if (!m_PlayerEditorConnectionEvents.messageTypeSubscribers.Exists(x => x.MessageTypeId == messageId))
            {
                GetEditorConnectionNativeApi().UnregisterInternal(messageId);
            }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Define a stable Guid for the message ID (Guid.Parse of a fixed string).
  2. Use a well-known message ID constant shared between editor and player.
  3. Validate messageId != Guid.Empty at the call site.

Example fix

// before
connection.Register(Guid.Empty, OnMsg);
// after
static readonly Guid k_MsgId = new Guid("d1b8...-...");
connection.Register(k_MsgId, OnMsg);
Defensive patterns

Strategy: validation

Validate before calling

if (messageId != Guid.Empty) connection.Register(messageId, callback);

Type guard

static bool IsValidMessageId(Guid id) => id != Guid.Empty;

Prevention

When it happens

Trigger: Calling EditorConnection.Register(Guid.Empty, callback) — passing an uninitialized Guid field or default(Guid).

Common situations: MessageId constant forgotten/never assigned, or a field left at its default. Copy-paste where the Guid was meant to be Guid.NewGuid() or a known message ID.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/a57d2db67f3f6ed3. Report an issue: GitHub.