{"record":{"id":"eb36fbf589fb5860","repo":"Unity-Technologies/UnityCsReference","slug":"could-not-find-socket-definition-name","errorCode":null,"errorMessage":"Could not find socket definition {name}.","messagePattern":"Could not find socket definition (.+?)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/PlayerSettingsXboxOne.bindings.cs","lineNumber":219,"sourceCode":"\n            [NativeMethod(\"RemoveXboxOneSocketDefinition\")]\n            [StaticAccessor(\"GetPlayerSettings().GetEditorOnlyForUpdate()\", StaticAccessorType.Dot)]\n            extern public static void RemoveSocketDefinition(string name);\n\n            [NativeMethod(\"SetXboxOneSocketDefinition\")]\n            [StaticAccessor(\"GetPlayerSettings().GetEditorOnlyForUpdate()\", StaticAccessorType.Dot)]\n            extern public static void SetSocketDefinition(string name, string port, int protocol, int[] usages, string templateName, int sessionRequirment, int[] deviceUsages);\n\n            [NativeMethod(\"GetXboxOneSocketDefinition\")]\n            [StaticAccessor(\"GetPlayerSettings().GetEditorOnlyForUpdate()\", StaticAccessorType.Dot)]\n            extern private static void GetSocketDefinitionInternal(string name, out string port, out int protocol, [Out] int[] usages, out string templateName, out int sessionRequirment, [Out] int[] deviceUsages);\n\n            public static void GetSocketDefinition(string name, out string port, out int protocol, out int[] usages, out string templateName, out int sessionRequirment, out int[] deviceUsages)\n            {\n                int numUsages = GetXboxOneSocketDefinitionNumUsages(name);\n                int numDeviceUsages = GetXboxOneSocketDefinitionNumDeviceUsages(name);\n                if (numUsages < 0 || numDeviceUsages < 0)\n                    throw new ArgumentException(\"Could not find socket definition \" + name + \".\");\n\n                usages = new int[numUsages];\n                deviceUsages = new int[numDeviceUsages];\n\n                GetSocketDefinitionInternal(name, out port, out protocol, usages, out templateName, out sessionRequirment, deviceUsages);\n            }\n\n            [StaticAccessor(\"GetPlayerSettings().GetEditorOnlyForUpdate()\", StaticAccessorType.Dot)]\n            extern public static string[] SocketNames\n            {\n                [NativeMethod(\"GetXboxOneSocketNames\")]\n                get;\n            }\n\n            [NativeMethod(\"GetXboxOneSocketDefinitionNumUsages\")]\n            [StaticAccessor(\"GetPlayerSettings().GetEditorOnlyForUpdate()\", StaticAccessorType.Dot)]\n            extern private static int GetXboxOneSocketDefinitionNumUsages(string name);\n","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/PlayerSettingsXboxOne.bindings.cs#L201-L237","documentation":"PlayerSettings.XboxOne.GetSocketDefinition queries the native Xbox One socket configuration by name. It first checks the usage count arrays via GetXboxOneSocketDefinitionNumUsages and GetXboxOneSocketDefinitionNumDeviceUsages; if either returns a negative value, the socket name was never registered with SetSocketDefinition. The method throws ArgumentException with the queried name so the caller can identify which socket is missing.","triggerScenarios":"Calling PlayerSettings.XboxOne.GetSocketDefinition(\"mySocket\", ...) when 'mySocket' was never created via SetSocketDefinition, or was removed via RemoveSocketDefinition before the query. Passing a typo'd or case-mismatched socket name.","commonSituations":"Build scripts that query Xbox One networking socket configuration before it has been initialized. Editor tools that enumerate sockets but reference a name from a different project or an outdated configuration. Case-sensitivity mismatches between SetSocketDefinition and GetSocketDefinition calls.","solutions":["Check PlayerSettings.XboxOne.SocketNames to verify the socket name exists before calling GetSocketDefinition","Ensure SetSocketDefinition has been called with the exact name (case-sensitive) before any GetSocketDefinition call","If the socket was removed, re-register it with SetSocketDefinition before querying","Log SocketNames to verify available sockets when debugging"],"exampleFix":"// before\nPlayerSettings.XboxOne.GetSocketDefinition(\"mySocket\", out port, out protocol, out usages, out template, out sessionReq, out deviceUsages);\n\n// after\nif (Array.IndexOf(PlayerSettings.XboxOne.SocketNames, \"mySocket\") >= 0)\n    PlayerSettings.XboxOne.GetSocketDefinition(\"mySocket\", out port, out protocol, out usages, out template, out sessionReq, out deviceUsages);\nelse\n    Debug.LogError($\"Socket 'mySocket' not found. Available: {string.Join(\", \", PlayerSettings.XboxOne.SocketNames)}\");","handlingStrategy":"validation","validationCode":"string socketName = \"mySocket\";\nstring[] existing = PlayerSettings.XboxOne.SocketNames;\nbool exists = Array.IndexOf(existing, socketName) >= 0;\n// Only call GetSocketDefinition if exists is true","typeGuard":null,"tryCatchPattern":"try\n{\n    PlayerSettings.XboxOne.GetSocketDefinition(name, out port, out protocol, out usages, out template, out sessionReq, out deviceUsages);\n}\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Could not find socket definition\"))\n{\n    Debug.LogError($\"Socket '{name}' not registered. Available: {string.Join(\", \", PlayerSettings.XboxOne.SocketNames)}\");\n}","preventionTips":["Always check SocketNames before calling GetSocketDefinition","Call SetSocketDefinition before GetSocketDefinition in initialization code","Log available socket names when debugging socket configuration issues"],"tags":["unity","xboxone","editor-scripting","playersettings","networking","socket","argumentexception"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}