{"record":{"id":"31c1ccb36480a9b8","repo":"bevyengine/bevy","slug":"expected-value-to-be-of-type-but-received","errorCode":null,"errorMessage":"Expected value to be of type {} but received {}","messagePattern":"Expected value to be of type (.+?) but received (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_reflect/src/serde/ser/serialize_with_registry.rs","lineNumber":80,"sourceCode":"    pub fn serialize<S>(\n        &self,\n        value: &dyn Reflect,\n        serializer: S,\n        registry: &TypeRegistry,\n    ) -> Result<S::Ok, S::Error>\n    where\n        S: Serializer,\n    {\n        ((self.serialize)(value, registry)).serialize(serializer)\n    }\n}\n\nimpl<T: Reflect + SerializeWithRegistry> CreateTypeData<T> for ReflectSerializeWithRegistry {\n    fn create_type_data(_input: ()) -> Self {\n        Self {\n            serialize: |value: &dyn Reflect, registry| {\n                let value = value.downcast_ref::<T>().unwrap_or_else(|| {\n                    panic!(\n                        \"Expected value to be of type {} but received {}\",\n                        core::any::type_name::<T>(),\n                        value.reflect_type_path()\n                    )\n                });\n                Box::new(SerializableWithRegistry { value, registry })\n            },\n        }\n    }\n}\n\nstruct SerializableWithRegistry<'a, T: SerializeWithRegistry> {\n    value: &'a T,\n    registry: &'a TypeRegistry,\n}\n\nimpl<'a, T: SerializeWithRegistry> Serialize for SerializableWithRegistry<'a, T> {\n    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_reflect/src/serde/ser/serialize_with_registry.rs#L62-L98","documentation":"Panic in ReflectSerializeWithRegistry's serialize closure (impl CreateTypeData): the dyn Reflect value could not be downcast to the concrete serializable type T — i.e. serialization type data was invoked with a value of the wrong concrete type (expected vs received paths in message). This indicates corrupted type data dispatch.","triggerScenarios":"Thrown at crates/bevy_reflect/src/serde/ser/serialize_with_registry.rs:80 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Serialize values of the type the serializer was created for","Check the type registration/dispatch that selected this serializer"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}