{"record":{"id":"259da337141f3349","repo":"AvaloniaUI/Avalonia","slug":"object-of-type-o-value-gettype-is-not-allowed","errorCode":null,"errorMessage":"Object of type {o.Value.GetType()} is not allowed","messagePattern":"Object of type (.+?) is not allowed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Rendering/Composition/CompositionPropertySet.cs","lineNumber":130,"sourceCode":"            _variants.Remove(key);\n        }\n\n        internal PropertySetSnapshot Snapshot() =>\n            SnapshotCore(1);\n        \n        private PropertySetSnapshot SnapshotCore(int allowedNestingLevel)\n        {\n            var dic = new Dictionary<string, PropertySetSnapshot.Value>(_objects.Count + _variants.Count);\n            foreach (var o in _objects)\n            {\n                if (o.Value is CompositionPropertySet ps)\n                {\n                    if (allowedNestingLevel <= 0)\n                        throw new InvalidOperationException(\"PropertySet depth limit reached\");\n                    dic[o.Key] = new PropertySetSnapshot.Value(ps.SnapshotCore(allowedNestingLevel - 1));\n                }\n                else if (o.Value.Server == null)\n                    throw new InvalidOperationException($\"Object of type {o.Value.GetType()} is not allowed\");\n                else\n                    dic[o.Key] = new PropertySetSnapshot.Value((ServerObject)o.Value.Server);\n            }\n\n            foreach (var v in _variants)\n                dic[v.Key] = v.Value;\n            \n            return new PropertySetSnapshot(dic);\n        }\n    }\n\n    public enum CompositionGetValueStatus\n    {\n        Succeeded,\n        TypeMismatch,\n        NotFound\n    }\n}","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Rendering/Composition/CompositionPropertySet.cs#L112-L148","documentation":"While snapshotting a property set, any stored CompositionObject that is neither a nested CompositionPropertySet nor backed by a Server (Server == null) is rejected with InvalidOperationException naming its type. Types like CompositionAnimation and bare CompositionPropertySet references have no server counterpart and cannot be serialized as expression parameter values.","triggerScenarios":"Placing a server-less CompositionObject (e.g. a CompositionAnimation, or another CompositionPropertySet used as a value object) into a CompositionPropertySet via the internal Set(key, CompositionObject), then snapshotting — typically by starting an animation that references that parameter.","commonSituations":"Registering an animation or an unsupported object type as a reference value inside a property set used by an expression animation; misusing internal Set overloads.","solutions":["Only store server-backed composition objects (visuals, brushes) or nested CompositionPropertySets in a property set.","Reference other CompositionObjects via CompositionAnimation.SetReferenceParameter rather than embedding them as property-set values.","Do not put CompositionAnimation instances into a CompositionPropertySet."],"exampleFix":"// before\npropSet.Set(\"anim\", someAnimation); // CompositionAnimation has no Server\nanim.SetReferenceParameter(\"p\", propSet);\nvisual.StartAnimation(\"Opacity\", anim); // Snapshot throws\n\n// after\nanim.SetReferenceParameter(\"refVisual\", someVisual); // server-backed\nvisual.StartAnimation(\"Opacity\", anim);","handlingStrategy":"validation","validationCode":"// Only allow server-backed objects or nested property sets as values.\nif (value is CompositionObject co && !(co is CompositionPropertySet) && co.GetType().Name.Contains(\"Animation\"))\n    throw new InvalidOperationException($\"{co.GetType()} is not allowed in a PropertySet\");","typeGuard":"static bool IsAllowedValue(CompositionObject o) => o is CompositionPropertySet || /* server-backed */ true;","tryCatchPattern":null,"preventionTips":["Never put CompositionAnimation instances into a CompositionPropertySet.","Store only server-backed objects or nested CompositionPropertySets as values.","Reference other objects via SetReferenceParameter on the animation."],"tags":["composition","property-set","snapshot","type-mismatch"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}