{"record":{"id":"7bf58c4f42e3b201","repo":"stride3d/stride","slug":"could-not-find-serializer-for-generic-dependent-type-0-when","errorCode":null,"errorMessage":"Could not find serializer for generic dependent type {0} when processing {1}","messagePattern":"Could not find serializer for generic dependent type (.+?) when processing (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.AssemblyProcessor/Serializers/CecilSerializerContext.cs","lineNumber":517,"sourceCode":"        // Detect all ldtoken (attributes would have been better, but unfortunately C# doesn't allow generics in attributes)\n        foreach (var inst in enumerateMethod.Body.Instructions)\n        {\n            if (inst.OpCode.Code != Code.Ldtoken)\n                continue;\n\n            var type = (TypeReference)inst.Operand;\n\n            // Try to \"close\" generics type with serializer type as a context\n            var dependentType = ResolveGenericsVisitor.Process(serializableTypeInfo.SerializerType, type);\n            if (dependentType.ContainsGenericParameter())\n                continue;\n\n            // Import type so that it becomes local to the assembly\n            // (otherwise SerializableTypeInfo.Local will be false and it won't be instantiated)\n            var importedType = Assembly.MainModule.ImportReference(dependentType);\n            if (ResolveSerializer(importedType) == null)\n            {\n                throw new InvalidOperationException(string.Format(\"Could not find serializer for generic dependent type {0} when processing {1}\", dependentType, dataType));\n            }\n        }\n    }\n\n    private ProfileInfo GetSerializableTypes(string profile)\n    {\n        if (!SerializableTypesProfiles.TryGetValue(profile, out var profileInfo))\n        {\n            profileInfo = new ProfileInfo();\n            SerializableTypesProfiles.Add(profile, profileInfo);\n        }\n        return profileInfo;\n    }\n\n    internal class SerializableTypeInfo\n    {\n        public TypeReference SerializerType { get; internal set; }\n        public DataSerializerGenericMode Mode { get; internal set; }","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.AssemblyProcessor/Serializers/CecilSerializerContext.cs#L499-L535","documentation":"ScanSerializerDependencies verifies that every generic argument (dependent type) of a registered serializable type has its own serializer. When ResolveSerializer returns null for one of them, this error is thrown naming the dependent type and the owner type.","triggerScenarios":"A generic serializable type like List<MyType> is registered, but MyType (the dependent type) has no resolvable serializer at that point — no DataContract, no DataSerializer, and not part of the current processing set.","commonSituations":"Using a custom class as a generic collection element without [DataContract]; a serializer assembly that references types from an assembly not being processed; typo in a namespace so the element type resolves to nothing.","solutions":["Add [DataContract] to the dependent type so a serializer is generated","Create/register an explicit DataSerializer for the dependent type","Ensure the assembly defining the dependent type is processed before/in the same run","Mark the member with [DataMemberIgnore] if the dependent type need not be serialized"],"exampleFix":"// before\npublic class Mesh { public List<VertData> Vertices; } // VertData not serializable\n// after\n[DataContract]\npublic class VertData { public float X, Y, Z; }","handlingStrategy":"validation","validationCode":"static void EnsureElementSerializable(Type collectionType)\n{\n    foreach (var arg in collectionType.GetGenericArguments())\n        if (!arg.IsDefined(typeof(DataContractAttribute)) && !arg.IsPrimitive && !arg.IsEnum)\n            throw new InvalidOperationException($\"{arg.Name} needs [DataContract] or a DataSerializer\");\n}","typeGuard":"static bool HasSerializer(Type t) =>\n    t.IsPrimitive || t.IsEnum || t == typeof(string) || t.IsDefined(typeof(DataContractAttribute));","tryCatchPattern":"try { ProcessCollection(listType); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"generic dependent type\"))\n{\n    logger.Error($\"Add a serializer for the element type: {ex.Message}\");\n}","preventionTips":["Every type used as a generic collection element in serialized data needs [DataContract]","Keep element types in processed assemblies","Run the processor locally before CI to catch missing serializers early"],"tags":["serialization","generics","missing-serializer"],"backgroundTag":"missing-dependency","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}