{"record":{"id":"6efed05a1652bb98","repo":"stride3d/stride","slug":"failed-to-get-objectdescriptor-for-type-0-the-member-1","errorCode":null,"errorMessage":"Failed to get ObjectDescriptor for type [{0}]. The member [{1}] cannot be registered as a member with the same name is already registered [{2}]","messagePattern":"Failed to get ObjectDescriptor for type \\[(.+?)\\]\\. The member \\[(.+?)\\] cannot be registered as a member with the same name is already registered \\[(.+?)\\]","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs","lineNumber":154,"sourceCode":"        if (keyComparer != null)\n        {\n            memberList.Sort(keyComparer);\n        }\n\n        // Free the member list\n        members = [.. memberList];\n\n        // If no members found, we don't need to build a dictionary map\n        if (members.Length == 0)\n            return;\n\n        mapMembers = new Dictionary<string, IMemberDescriptor>(members.Length);\n\n        foreach (var member in members)\n        {\n            if (mapMembers.TryGetValue(member.Name, out var existingMember))\n            {\n                throw new InvalidOperationException(\"Failed to get ObjectDescriptor for type [{0}]. The member [{1}] cannot be registered as a member with the same name is already registered [{2}]\".ToFormat(Type.FullName, member, existingMember));\n            }\n\n            mapMembers.Add(member.Name, member);\n\n            // If there is any alternative names, register them\n            if (member.AlternativeNames != null)\n            {\n                foreach (var alternateName in member.AlternativeNames)\n                {\n                    if (mapMembers.TryGetValue(alternateName, out existingMember))\n                    {\n                        throw new InvalidOperationException($\"Failed to get ObjectDescriptor for type [{Type.FullName}]. The member [{member}] cannot be registered as a member with the same name [{alternateName}] is already registered [{existingMember}]\");\n                    }\n                    remapMembers ??= [];\n\n                    mapMembers[alternateName] = member;\n                    remapMembers.Add(alternateName);\n                }","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs#L136-L172","documentation":"During ObjectDescriptor.Initialize, members are registered by name into mapMembers; if two members resolve to the same serialized name (after naming-convention processing), the descriptor cannot disambiguate them and throws InvalidOperationException. This is an internal invariant: a type where two distinct members produce identical keys would make serialization ambiguous.","triggerScenarios":"Constructing an ObjectDescriptor (directly or via TypeDescriptorFactory) for a type containing two members with identical names after convention processing — e.g. duplicate property/field names, a field and property with the same name, or shadowed members from inheritance both returned by GetMembers.","commonSituations":"Types using unusual naming conventions (camelCase/snake_case conversions collapsing 'FooBar' and 'foo_bar' style pairs); shadowing members with the 'new' keyword in derived classes; generated/DTO code with duplicate names.","solutions":["Rename or remove one of the conflicting members in the target type.","Use [DataMember]/[YamlMember]-style attributes to give one member a distinct serialized name.","Check inheritance: hide the base member properly or exclude it via [DoNotSerialize]/ignore attributes so it is not scanned twice.","Fix the naming convention so it does not collapse distinct member names to the same key."],"exampleFix":"// before\npublic class Data\n{\n    public int Value;\n    public int Value { get; set; }\n}\n// after\npublic class Data\n{\n    public int Value { get; set; }\n}","handlingStrategy":"validation","validationCode":"var names = type.GetMembers()\n    .Where(m => m is FieldInfo or PropertyInfo)\n    .Select(m => NamingHelper.Convert(m.Name, convention))\n    .GroupBy(n => n, StringComparer.Ordinal)\n    .Where(g => g.Count() > 1).ToList();\nif (names.Count > 0) throw new InvalidOperationException($\"Duplicate member names: {string.Join(\", \", names)}\");","typeGuard":null,"tryCatchPattern":"try { var desc = TypeDescriptorFactory.Default.FindDescriptor(type); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"cannot be registered as a member\")) { log.LogError(ex, \"Type {Type} has duplicate member names\", type); }","preventionTips":["Avoid field/property pairs with the same name in serialized types.","Do not shadow base-class members with 'new' in serializable types.","Check that naming conventions don't collapse distinct member names.","Run descriptor construction over all serializable types in CI."],"tags":["reflection","duplicate-member","serialization","csharp"],"backgroundTag":"internal-invariant-violation","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"}