{"record":{"id":"3538aeb1ab9f52c0","repo":"stride3d/stride","slug":"obj-is-not-the-same-type-as-this-instance","errorCode":null,"errorMessage":"obj is not the same type as this instance.","messagePattern":"obj is not the same type as this instance\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Quantum/NodeIndex.cs","lineNumber":101,"sourceCode":"\n    /// <inheritdoc/>\n    public override readonly bool Equals(object? obj)\n    {\n        if (ReferenceEquals(null, obj)) return false;\n        return obj is NodeIndex nodeIndex && Equals(nodeIndex);\n    }\n\n    /// <inheritdoc/>\n    public override readonly int GetHashCode()\n    {\n        return Value?.GetHashCode() ?? 0;\n    }\n\n    /// <inheritdoc/>\n    readonly int IComparable.CompareTo(object? obj)\n    {\n        if (obj is not NodeIndex nodeIndex)\n            throw new ArgumentException(\"obj is not the same type as this instance.\", nameof(obj));\n\n        return CompareTo(nodeIndex);\n    }\n\n    public static bool operator ==(NodeIndex a, NodeIndex b)\n    {\n        return Equals(a.Value, b.Value);\n    }\n\n    /// <inheritdoc/>\n    public static bool operator !=(NodeIndex a, NodeIndex b)\n    {\n        return !Equals(a.Value, b.Value);\n    }\n}\n","sourceCodeStart":83,"sourceCodeEnd":117,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Quantum/NodeIndex.cs#L83-L117","documentation":"NodeIndex implements IComparable, and the explicit IComparable.CompareTo(object) overload requires the boxed argument to be a NodeIndex. Because the non-generic IComparable interface accepts any object, the library validates the runtime type and throws ArgumentException when the caller passes a different type. The strongly-typed CompareTo(NodeIndex) overload never throws this.","triggerScenarios":"Calling the explicit IComparable.CompareTo(object) implementation (e.g. via a non-generic IComparable reference, sorting APIs, or reflection) with an argument whose runtime type is not NodeIndex, such as null, an int, or another index-like struct.","commonSituations":"Passing a NodeIndex into a legacy non-generic sort/collection API that boxes values as object; comparing NodeIndex to an integer index or a Guid by mistake; using ArrayList or IComparer non-generic pipelines where the item type was assumed.","solutions":["Pass an actual NodeIndex instance (obtain it from the node/graph API) rather than a raw int, Guid, or other index representation","Check the runtime type with 'obj is NodeIndex' before invoking CompareTo via an IComparable reference","Prefer the strongly-typed CompareTo(NodeIndex) overload or the ==/!= operators, which are statically typed and cannot hit this throw","If comparing distinct index representations, convert the foreign value to a NodeIndex first (the library constructs NodeIndex values internally, e.g. via NodeIndex.Empty or node APIs)"],"exampleFix":"// before\nIComparable cmp = nodeIndex;\nint r = cmp.CompareTo(42); // ArgumentException\n// after\nif (other is NodeIndex ni)\n    int r = cmp.CompareTo(ni);\nelse\n    int r = nodeIndex.CompareTo(NodeIndex.Empty); // or handle type explicitly","handlingStrategy":"type-guard","validationCode":"if (obj is not NodeIndex) throw new InvalidOperationException(\"CompareTo requires a NodeIndex\");","typeGuard":"static bool IsNodeIndex(object? obj) => obj is NodeIndex;","tryCatchPattern":"try { result = comparable.CompareTo(candidate); }\ncatch (ArgumentException ex) when (ex.ParamName == \"obj\")\n{ /* handle non-NodeIndex argument: skip or convert */ }","preventionTips":["Use the generic IComparable<NodeIndex> interface surface instead of non-generic IComparable","Never pass boxed primitives or Guids to CompareTo","Rely on == / != operators for NodeIndex equality checks"],"tags":["csharp","argument","type-mismatch","comparable"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}