stride3d/stride · error · InvalidOperationException

Can't find serializer for type

Error message

Can't find serializer for type {0}

What it means

When a [DataSerializer] type's target data type is known but no serializer type has been established, ProcessDataSerializerGlobalAttributes calls context.ResolveSerializer(dataType); if that returns null (no serializer can be produced for the type), this error is thrown.

Solutions

  1. Verify the target type is annotated [DataContract] or has an existing DataSerializer
  2. Check that the target type's own serializer dependencies resolve (see error 194)
  3. Ensure the correct profile is being processed where the serializer exists
  4. Fix namespace/type name in the DataSerializer attribute after renames

Example fix

// before
[DataSerializer(typeof(UnmarkedType))]
class S : DataSerializer<UnmarkedType> {}
// after
[DataContract]
public class UnmarkedType { ... }
Defensive patterns

Strategy: validation

Validate before calling

if (!targetType.IsDefined(typeof(DataContractAttribute)) && !HasRegisteredSerializer(targetType))
    throw new InvalidOperationException($"{targetType} must have [DataContract] or a DataSerializer before use in [DataSerializer] attribute");

Type guard

static bool IsResolvableSerializerTarget(Type t) =>
    t != null && (t.IsDefined(typeof(DataContractAttribute)) || HasRegisteredSerializer(t));

Try / catch

try { ProcessGlobalAttributes(); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Can't find serializer for type"))
{
    logger.Error($"Serializer target missing: {ex.Message}. Add [DataContract] or a DataSerializer.");
}

Prevention

When it happens

Trigger: A type is referenced as a serialization target but ResolveSerializer returns null: the type has no generated serializer, is not marked serializable, or its serializer dependencies failed to resolve for the given profile.

Common situations: Pointing [DataSerializer(typeof(MyType))] at a type the processor cannot serialize; profile mismatch so the serializer only exists for another graphics profile; typo/renamed type so the attribute target no longer resolves.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/c26d3eea332e77b4. Report an issue: GitHub.

Appendix: source

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

            {
                if (mode == DataSerializerGenericMode.None)
                    dataType = FindSerializerDataType(dataSerializerType);
                else
                    throw new InvalidOperationException("Can't deduce data serializer type for generic types.");
            }

            // Reading from custom arguments doesn't have its ValueType properly set
            dataType = dataType.FixupValueType();
            dataSerializerType = dataSerializerType?.FixupValueType();

            CecilSerializerContext.SerializableTypeInfo serializableTypeInfo;

            if (dataSerializerType == null)
            {
                // TODO: We should avoid calling ResolveSerializer now just to have the dataSerializerType (we should do so only in a second step)
                serializableTypeInfo = context.ResolveSerializer(dataType, profile: profile);
                if (serializableTypeInfo == null)
                    throw new InvalidOperationException(string.Format("Can't find serializer for type {0}", dataType));
                serializableTypeInfo.Local = local;
                serializableTypeInfo.ExistingLocal = local;
                dataSerializerType = serializableTypeInfo.SerializerType;
            }
            else
            {
                // Add it to list of serializable types
                serializableTypeInfo = new CecilSerializerContext.SerializableTypeInfo(dataSerializerType, local, mode) { ExistingLocal = local, Inherited = inherited, IsGeneratedSerializer = complexSerializer };
                context.AddSerializableType(dataType, serializableTypeInfo, profile);
            }
        }
    }

    public static TypeReference FindSerializerDataType(TypeReference dataSerializerType)
    {
        // Find "DataSerializer<T>" base and its dataType (T)
        TypeReference dataType = null;
        var dataSerializerTypeCurrent = dataSerializerType;

View on GitHub (pinned to 96fad776d2)