EllanJiang/GameFramework · error · GameFrameworkException

Type of value is invalid.

Error message

Type of value is invalid.

What it means

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).

Solutions

  1. Only pass ResourceName instances to CompareTo; use the typed overload CompareTo(ResourceName)
  2. Use generic collections (List<ResourceName>, SortedSet<ResourceName>) instead of non-generic ones
  3. Check the value's type with `is ResourceName` before calling the object overload

Example fix

// before
int result = name.CompareTo((object)"SomeResource");
// after
var other = value as ResourceName?;
int result = other.HasValue ? name.CompareTo(other.Value) : throw new ArgumentException("Value is not a ResourceName");
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is ResourceName other) { int r = name.CompareTo(other); }

Type guard

bool IsResourceName(object value) => value is ResourceName;

Try / catch

try { int r = name.CompareTo(value); } catch (GameFrameworkException ex) { Log.Error("CompareTo requires a ResourceName instance: " + ex.Message); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/7f7f8d592c855e42. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.ResourceName.cs:144

            {
                return a.Equals(b);
            }

            public static bool operator !=(ResourceName a, ResourceName b)
            {
                return !(a == b);
            }

            public int CompareTo(object value)
            {
                if (value == null)
                {
                    return 1;
                }

                if (!(value is ResourceName))
                {
                    throw new GameFrameworkException("Type of value is invalid.");
                }

                return CompareTo((ResourceName)value);
            }

            public int CompareTo(ResourceName resourceName)
            {
                int result = string.CompareOrdinal(m_Name, resourceName.m_Name);
                if (result != 0)
                {
                    return result;
                }

                result = string.CompareOrdinal(m_Variant, resourceName.m_Variant);
                if (result != 0)
                {
                    return result;
                }

View on GitHub (pinned to d0c010b051)