{"record":{"id":"f46737f3fa21a185","repo":"stride3d/stride","slug":"unable-to-extract-asset-reference-from-object-objectcontext","errorCode":null,"errorMessage":"Unable to extract asset reference from object [{objectContext.Instance}]","messagePattern":"Unable to extract asset reference from object \\[(.+?)\\]","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Serializers/ContentReferenceSerializer.cs","lineNumber":35,"sourceCode":"    {\n        return AssetRegistry.IsExactContentType(type);\n    }\n\n    public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar)\n    {\n        if (!AssetReference.TryParse(fromScalar.Value, out var guid, out var location))\n        {\n            throw new YamlException(fromScalar.Start, fromScalar.End, \"Unable to decode asset reference [{0}]. Expecting format GUID:LOCATION\".ToFormat(fromScalar.Value));\n        }\n\n        var instance = AttachedReferenceManager.CreateProxyObject(context.Descriptor.Type, guid, ReferenceSerializationHelper.RestoreLocation(ref context, location.FullPath));\n        return instance;\n    }\n\n    public override string ConvertTo(ref ObjectContext objectContext)\n    {\n        var attachedReference = AttachedReferenceManager.GetAttachedReference(objectContext.Instance)\n            ?? throw new YamlException($\"Unable to extract asset reference from object [{objectContext.Instance}]\");\n        return ReferenceSerializationHelper.FormatReference(ref objectContext, attachedReference.Id, attachedReference.Url);\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":39,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Serializers/ContentReferenceSerializer.cs#L17-L39","documentation":"ContentReferenceSerializer.ConvertTo serializes an object back to a YAML string by fetching its attached reference (id + url) through AttachedReferenceManager.GetAttachedReference. When the instance carries no attached reference — meaning it is not a proxy object created with an id/url — it throws YamlException. The library cannot serialize a plain instance as a content reference.","triggerScenarios":"Saving an asset graph where a field holds a concrete, fully-loaded instance (or a manually constructed object) instead of the AttachedReferenceManager proxy; calling ConvertTo on an object created with Activator/new instead of loaded from a reference.","commonSituations":"Custom code that replaces a proxy reference with a real instance at runtime and then saves the asset; constructing scene/asset objects programmatically without going through the reference system; serialization after an undo/redo that swapped in live objects.","solutions":["Ensure the object being serialized is the proxy created via AttachedReferenceManager.CreateProxyObject (or loaded from an asset), not a manually instantiated instance.","If you replaced a reference with a live instance, restore the proxy (or re-create it with the original guid/url) before saving.","Add a pre-save check: call AttachedReferenceManager.GetAttachedReference(obj) yourself and repair objects that return null.","Keep runtime-resolved instances out of serialized asset graphs; resolve references after deserialization instead."],"exampleFix":"// before: plain instance cannot be serialized as a reference\nmodel = new Model();\nasset.Model = model;\n\n// after: keep the attached-reference proxy in the serialized graph\nasset.Model = AttachedReferenceManager.CreateProxyObject<Model>(guid, new UFile(\"mymodel\"));","handlingStrategy":"type-guard","validationCode":"if (AttachedReferenceManager.GetAttachedReference(instance) is null)\n    throw new InvalidOperationException(\"Instance has no attached reference; create it via AttachedReferenceManager.CreateProxyObject before serializing.\");","typeGuard":"bool IsReferenceProxy(object o) => AttachedReferenceManager.GetAttachedReference(o) != null;","tryCatchPattern":"try { return serializer.ConvertTo(ref objectContext); }\ncatch (YamlException) { /* replace instance with a proxy created from a known guid/url */ }","preventionTips":["Keep attached-reference proxies in serialized graphs, not live instances","Resolve references after deserialization, not before serialization","Re-create proxies with CreateProxyObject after runtime substitution","Pre-save check every content-reference field with GetAttachedReference"],"tags":["yaml","serialization","proxy","asset-reference"],"backgroundTag":"invalid-argument-value","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"}