{"record":{"id":"7f7f8d592c855e42","repo":"EllanJiang/GameFramework","slug":"type-of-value-is-invalid","errorCode":null,"errorMessage":"Type of value is invalid.","messagePattern":"Type of value is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceName.cs","lineNumber":144,"sourceCode":"            {\n                return a.Equals(b);\n            }\n\n            public static bool operator !=(ResourceName a, ResourceName b)\n            {\n                return !(a == b);\n            }\n\n            public int CompareTo(object value)\n            {\n                if (value == null)\n                {\n                    return 1;\n                }\n\n                if (!(value is ResourceName))\n                {\n                    throw new GameFrameworkException(\"Type of value is invalid.\");\n                }\n\n                return CompareTo((ResourceName)value);\n            }\n\n            public int CompareTo(ResourceName resourceName)\n            {\n                int result = string.CompareOrdinal(m_Name, resourceName.m_Name);\n                if (result != 0)\n                {\n                    return result;\n                }\n\n                result = string.CompareOrdinal(m_Variant, resourceName.m_Variant);\n                if (result != 0)\n                {\n                    return result;\n                }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceName.cs#L126-L162","documentation":"ResourceName.CompareTo(object value) throws this when the boxed argument is not a ResourceName instance. This implements IComparable's object overload, which requires a runtime type check before delegating to the strongly-typed CompareTo(ResourceName).","triggerScenarios":"Calling `resourceName.CompareTo(someObject)` where someObject is a string, another struct, or null-typed value that is not ResourceName; sorting collections via non-generic IComparer paths that pass mismatched element types.","commonSituations":"Using ResourceName in non-generic sorted collections (e.g. ArrayList) mixed with other types; reflection-based comparison code; LINQ code paths where a cast to object erased the type.","solutions":["Only pass ResourceName instances to CompareTo; use the typed overload CompareTo(ResourceName)","Use generic collections (List<ResourceName>, SortedSet<ResourceName>) instead of non-generic ones","Check the value's type with `is ResourceName` before calling the object overload"],"exampleFix":"// before\nint result = name.CompareTo((object)\"SomeResource\");\n// after\nvar other = value as ResourceName?;\nint result = other.HasValue ? name.CompareTo(other.Value) : throw new ArgumentException(\"Value is not a ResourceName\");","handlingStrategy":"type-guard","validationCode":"if (value is ResourceName other) { int r = name.CompareTo(other); }","typeGuard":"bool IsResourceName(object value) => value is ResourceName;","tryCatchPattern":"try { int r = name.CompareTo(value); } catch (GameFrameworkException ex) { Log.Error(\"CompareTo requires a ResourceName instance: \" + ex.Message); }","preventionTips":["Prefer the strongly-typed CompareTo(ResourceName) overload","Use generic collections instead of ArrayList-style non-generic containers","Never mix heterogeneous types in collections sorted by ResourceName"],"tags":["csharp","gameframework","type-mismatch","icomparable"],"backgroundTag":"type-mismatch","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}