stride3d/stride · error · InvalidOperationException

Unable to find a serializer for the type

Error message

Unable to find a serializer for the type [{typeDescriptor.Type}]

What it means

GetSerializer throws InvalidOperationException when, even after querying and adding every registered IYamlSerializableFactory, no IYamlSerializable could be produced for the requested type. It means the type is not covered by any built-in or registered serializer factory.

Solutions

  1. Implement an IYamlSerializable (or factory) for the type and register it via TryAddFactory before sealing.
  2. Check whether the type is supported by the built-in serializers (primitives, collections, data contracts); if not, register a custom one.
  3. Inspect typeDescriptor.Type in the message to confirm exactly which type lacks a serializer.
  4. Ensure the factory's CanAddSerializerFactory/TryCreate logic accepts the type (fix overly strict filters).
  5. Add [DataContract]/[DataMember] or a YamlSerializer override for the type as appropriate.

Example fix

// before
selector.TryAddFactory(new BuiltinFactory());
selector.Seal();
// Deserialize(typeof(MyCustomType)) -> "Unable to find a serializer for the type [MyCustomType]"
// after
selector.TryAddFactory(new BuiltinFactory());
selector.TryAddFactory(new MyCustomTypeSerializerFactory());
selector.Seal();
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight: ensure every model type has a serializer
foreach (var t in modelTypes)
    if (!supportedTypes.Contains(t)) throw new InvalidOperationException($"No YAML serializer registered for {t}");

Try / catch

try { return serializer.Deserialize(reader, type); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Unable to find a serializer"))
{
    throw new NotSupportedException($"Type {type} needs a custom IYamlSerializableFactory registered before sealing", ex);
}

Prevention

When it happens

Trigger: Deserializing/serializing a type for which no factory returns a serializer — e.g. exotic generic constructs, interfaces without registered handling, types excluded by CanAddSerializerFactory, or a custom factory that returns null from TryCreate.

Common situations: Adding new asset/data types to a Stride project without registering serializers; third-party types in your data model; types whose descriptors were altered by custom TypeDescriptorFactory configuration; regressions after upgrading the library.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Serialization/SerializerFactorySelector.cs:69

                serializerLock.EnterWriteLock();
                if (!serializers.TryGetValue(typeDescriptor.Type, out serializer))
                {
                    foreach (var factory in factories)
                    {
                        serializer = factory.TryCreate(context, typeDescriptor);
                        if (serializer != null)
                        {
                            serializers.Add(typeDescriptor.Type, serializer);
                            break;
                        }
                    }
                }
                serializerLock.ExitWriteLock();
            }

            if (serializer == null)
            {
                throw new InvalidOperationException($"Unable to find a serializer for the type [{typeDescriptor.Type}]");
            }

            return serializer;
        }

        /// <summary>
        /// Indicates whether the given factory is supported by this selector.
        /// </summary>
        /// <param name="factory">The factory to evaluate.</param>
        /// <returns>True if the factory can be added to this selector, False otherwise.</returns>
        protected abstract bool CanAddSerializerFactory(IYamlSerializableFactory factory);
    }
}

View on GitHub (pinned to 96fad776d2)