stride3d/stride · error · InvalidOperationException

Could not determine data type for

Error message

Could not determine data type for {0}.

What it means

FindSerializerDataType walks the serializer's base types (via ResolveGenericsVisitor) to determine which data type the serializer serializes. If after walking all base types no data type was found, it throws this error instead of returning null.

Solutions

  1. Make the serializer inherit directly (or transitively with closed generics) from DataSerializer<YourType>
  2. Check the base-type chain and close all generic parameters along it
  3. Specify the data type explicitly where the API allows instead of relying on deduction

Example fix

// before
class MySerializer : SerializerBase { } // wrong base
// after
class MySerializer : DataSerializer<MyType> { }
Defensive patterns

Strategy: type-guard

Validate before calling

static bool HasDataSerializerBase(Type t)
{
    for (var b = t.BaseType; b != null; b = b.BaseType)
        if (b.IsGenericType && b.GetGenericTypeDefinition() == typeof(DataSerializer<>) && !b.ContainsGenericParameters)
            return true;
    return false;
}

Type guard

static bool IsWellFormedSerializer(Type t) =>
    typeof(DataSerializer).IsAssignableFrom(t) && HasDataSerializerBase(t);

Try / catch

try { RegisterSerializer(serializerType); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Could not determine data type"))
{
    logger.Error($"{serializerType} must (transitively) derive from a closed DataSerializer<T>");
}

Prevention

When it happens

Trigger: A DataSerializer subclass whose base-type chain never reaches a closed DataSerializer<T> (e.g. serializer derives from an abstract/open intermediate class without closing the generic, or derives from the wrong base).

Common situations: Hand-written serializer inheriting from a custom intermediate base class; copy-pasted serializer missing the DataSerializer<T> base; generic arity mismatch while resolving base types.

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 stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/806b09cb2ae43cc4. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.AssemblyProcessor/Serializers/ReferencedAssemblySerializerProcessor.cs:120

        // Find "DataSerializer<T>" base and its dataType (T)
        TypeReference dataType = null;
        var dataSerializerTypeCurrent = dataSerializerType;
        while (dataSerializerTypeCurrent != null)
        {
            if (dataSerializerTypeCurrent is GenericInstanceType genericInstanceType)
            {
                if (genericInstanceType.ElementType.FullName == "Stride.Core.Serialization.DataSerializer`1")
                {
                    dataType = genericInstanceType.GenericArguments[0];
                    break;
                }
            }

            dataSerializerTypeCurrent = ResolveGenericsVisitor.Process(dataSerializerTypeCurrent, dataSerializerTypeCurrent.Resolve().BaseType);
        }

        if (dataType == null)
            throw new InvalidOperationException(string.Format("Could not determine data type for {0}.", dataSerializerType));
        return dataType;
    }
}

View on GitHub (pinned to 96fad776d2)