Unity-Technologies/UnityCsReference · error · ArgumentException
Could not find socket definition
Error message
Could not find socket definition {name}. What it means
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.
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
Example fix
// before
PlayerSettings.XboxOne.GetSocketDefinition("mySocket", out port, out protocol, out usages, out template, out sessionReq, out deviceUsages);
// after
if (Array.IndexOf(PlayerSettings.XboxOne.SocketNames, "mySocket") >= 0)
PlayerSettings.XboxOne.GetSocketDefinition("mySocket", out port, out protocol, out usages, out template, out sessionReq, out deviceUsages);
else
Debug.LogError($"Socket 'mySocket' not found. Available: {string.Join(", ", PlayerSettings.XboxOne.SocketNames)}"); Defensive patterns
Strategy: validation
Validate before calling
string socketName = "mySocket"; string[] existing = PlayerSettings.XboxOne.SocketNames; bool exists = Array.IndexOf(existing, socketName) >= 0; // Only call GetSocketDefinition if exists is true
Try / catch
try
{
PlayerSettings.XboxOne.GetSocketDefinition(name, out port, out protocol, out usages, out template, out sessionReq, out deviceUsages);
}
catch (ArgumentException ex) when (ex.Message.StartsWith("Could not find socket definition"))
{
Debug.LogError($"Socket '{name}' not registered. Available: {string.Join(", ", PlayerSettings.XboxOne.SocketNames)}");
} Prevention
- Always check SocketNames before calling GetSocketDefinition
- Call SetSocketDefinition before GetSocketDefinition in initialization code
- Log available socket names when debugging socket configuration issues
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- PersistentLocalStorageSize must be between 256 and 4096…
- Given input object is not a prefab asset
- Object to create variant from has to be a Prefab root
- PlayerSettings.packageLogo140 is deprecated. Use…
- PlayerSettings.packageLogo140 is deprecated. Use…
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/eb36fbf589fb5860.
Report an issue: GitHub.
Appendix: source
Thrown at Editor/Mono/PlayerSettingsXboxOne.bindings.cs:219
[NativeMethod("RemoveXboxOneSocketDefinition")]
[StaticAccessor("GetPlayerSettings().GetEditorOnlyForUpdate()", StaticAccessorType.Dot)]
extern public static void RemoveSocketDefinition(string name);
[NativeMethod("SetXboxOneSocketDefinition")]
[StaticAccessor("GetPlayerSettings().GetEditorOnlyForUpdate()", StaticAccessorType.Dot)]
extern public static void SetSocketDefinition(string name, string port, int protocol, int[] usages, string templateName, int sessionRequirment, int[] deviceUsages);
[NativeMethod("GetXboxOneSocketDefinition")]
[StaticAccessor("GetPlayerSettings().GetEditorOnlyForUpdate()", StaticAccessorType.Dot)]
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);
public static void GetSocketDefinition(string name, out string port, out int protocol, out int[] usages, out string templateName, out int sessionRequirment, out int[] deviceUsages)
{
int numUsages = GetXboxOneSocketDefinitionNumUsages(name);
int numDeviceUsages = GetXboxOneSocketDefinitionNumDeviceUsages(name);
if (numUsages < 0 || numDeviceUsages < 0)
throw new ArgumentException("Could not find socket definition " + name + ".");
usages = new int[numUsages];
deviceUsages = new int[numDeviceUsages];
GetSocketDefinitionInternal(name, out port, out protocol, usages, out templateName, out sessionRequirment, deviceUsages);
}
[StaticAccessor("GetPlayerSettings().GetEditorOnlyForUpdate()", StaticAccessorType.Dot)]
extern public static string[] SocketNames
{
[NativeMethod("GetXboxOneSocketNames")]
get;
}
[NativeMethod("GetXboxOneSocketDefinitionNumUsages")]
[StaticAccessor("GetPlayerSettings().GetEditorOnlyForUpdate()", StaticAccessorType.Dot)]
extern private static int GetXboxOneSocketDefinitionNumUsages(string name);
View on GitHub (pinned to 225b0fbdb5)