{"record":{"id":"4c0a95e741821fef","repo":"stride3d/stride","slug":"unable-to-extract-url-reference-from-object-objectcontext","errorCode":null,"errorMessage":"Unable to extract url reference from object [{objectContext.Instance}]","messagePattern":"Unable to extract url reference from object \\[(.+?)\\]","errorType":"exception","errorClass":"YamlException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Serializers/UrlReferenceSerializer.cs","lineNumber":39,"sourceCode":"\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 url reference [{0}]. Expecting format GUID:LOCATION\".ToFormat(fromScalar.Value));\n        }\n\n        return UrlReferenceBase.New(context.Descriptor.Type, guid, ReferenceSerializationHelper.RestoreLocation(ref context, location.FullPath));\n    }\n\n    public override string ConvertTo(ref ObjectContext objectContext)\n    {\n        if (objectContext.Instance is UrlReferenceBase urlReference)\n        {\n            return ReferenceSerializationHelper.FormatReference(ref objectContext, urlReference.Id, urlReference.Url);\n        }\n\n        throw new YamlException($\"Unable to extract url reference from object [{objectContext.Instance}]\");\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":42,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Serializers/UrlReferenceSerializer.cs#L21-L42","documentation":"UrlReferenceSerializer.ConvertTo serializes UrlReferenceBase instances back to 'GUID:LOCATION' scalars. If the object being serialized is not actually a UrlReferenceBase (pattern match fails), the serializer cannot extract Id and Url and throws this YamlException.","triggerScenarios":"Serializing an object declared or cast as a UrlReference type whose runtime instance is not a UrlReferenceBase — e.g. a null instance, a wrong wrapper type assigned to the field, or a custom class deriving from something else stored in a UrlReference-typed slot.","commonSituations":"Custom serialization of objects with mistyped UrlReference fields; assigning null or a string to a UrlReference property before saving; bugs in generated or hand-written code that swaps field types during upgrades.","solutions":["Ensure the instance stored in the field is a UrlReferenceBase (e.g. UrlReference<T>) with valid Id and Url before saving","Fix code that assigns null or a different type to UrlReference-typed fields","If the value should be optional, make the property nullable and skip serialization for null","Debug the object at objectContext.Instance to see the actual runtime type"],"exampleFix":"// before\nurlField = \"myTexture.png\";\n// after\nurlField = new UrlReference<Texture>(new Guid(\"8f2a5c3e-1b4d-4a9c-b7e0-3d6f8a2c5e91\"), \"myTexture.png\");","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"bool IsValidUrlReferenceObject(object? o) => o is UrlReferenceBase { Id: var id, Url: var url } && id != Guid.Empty && !string.IsNullOrEmpty(url);","tryCatchPattern":"try { ConvertTo(ref objectContext); } catch (YamlException ex) when (ex.Message.Contains(\"Unable to extract url reference\")) { log.Error($\"Instance is not UrlReferenceBase: {ex.Message}\"); throw; }","preventionTips":["Check field types with pattern matching before saving objects containing UrlReferences","Never assign null or plain strings to UrlReference-typed members","Write unit tests that round-trip objects through the asset serializer"],"tags":["yaml","serialization","type-mismatch","url-reference"],"backgroundTag":"type-mismatch","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"}