{"record":{"id":"7886fe2486fe8c8b","repo":"stride3d/stride","slug":"unable-to-retrieve-value-for-0","errorCode":null,"errorMessage":"Unable to retrieve value for [{0}]","messagePattern":"Unable to retrieve value for \\[(.+?)\\]","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/PropertyContainer.cs","lineNumber":293,"sourceCode":"    }\n\n    /// <summary>\n    /// Gets the value of a property key or throw an error if the value was not found\n    /// </summary>\n    /// <typeparam name=\"T\">Type of the property key</typeparam>\n    /// <param name=\"propertyKey\">The property key.</param>\n    /// <returns>The value associated with this property key.</returns>\n    /// <exception cref=\"ArgumentNullException\">propertyKey</exception>\n    /// <exception cref=\"ArgumentException\">Unable to retrieve value for [{0}].ToFormat(propertyKey)</exception>\n    public T GetSafe<T>(PropertyKey<T> propertyKey)\n    {\n        ArgumentNullException.ThrowIfNull(propertyKey);\n        if (propertyKey.IsValueType)\n        {\n            return Get(propertyKey);\n        }\n\n        var result = Get(propertyKey, false) ?? throw new ArgumentException(\"Unable to retrieve value for [{0}]\".ToFormat(propertyKey));\n        return (T)result;\n    }\n\n    /// <summary>\n    /// Gets the specified tag value.\n    /// </summary>\n    /// <typeparam name=\"T\">Type of the tag value</typeparam>\n    /// <param name=\"propertyKey\">The tag property.</param>\n    /// <returns>Typed value of the tag property</returns>\n    public T? Get<T>(PropertyKey<T> propertyKey)\n    {\n        ArgumentNullException.ThrowIfNull(propertyKey);\n        if (propertyKey.IsValueType)\n        {\n            // Fast path for value type\n            // First, check if there is an accessor\n            if (propertyKey.AccessorMetadata != null)\n            {","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/PropertyContainer.cs#L275-L311","documentation":"PropertyContainer.GetSafe<T> is the strict variant of Get: for reference-type property keys it demands that a value exists and throws ArgumentException (with the key formatted into the message) when Get returns null. Use it only when absence of the property is a bug; the non-safe Get returns the default instead.","triggerScenarios":"Calling container.GetSafe(key) for a PropertyKey that was never set on that object (and has no default value producing a stored result) — Get(propertyKey, false) yields null and the exception is thrown.","commonSituations":"Reading an attached property before any code assigned it; key registered on a different owner type than expected; assuming a default exists when the key's default metadata is null; deserialized objects missing the property.","solutions":["Check the property is set (Get(key) != null or ContainsKey) before calling GetSafe.","Use non-throwing Get(key) and handle the default value instead.","Assign the property (or give the PropertyKey a default value metadata) before reading.","Verify you are querying the same PropertyKey instance and owner type used when setting."],"exampleFix":"// before\nvar name = properties.GetSafe(MyKeys.NameProperty); // throws if unset\n// after\nif (properties.TryGetValue(MyKeys.NameProperty, out var name2)) { ... }\n// or\nvar name3 = properties.Get(MyKeys.NameProperty); // returns default","handlingStrategy":"try-catch","validationCode":"if (properties.Get(myKey) is null)\n    throw new InvalidOperationException($\"Property {myKey.Name} not set before GetSafe\");","typeGuard":"static bool HasValue<T>(PropertyContainer c, PropertyKey<T> k) where T : class => c.Get(k) != null;","tryCatchPattern":"try { var v = properties.GetSafe(key); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Unable to retrieve value for\"))\n{\n    // property was never set; fall back to default or initialize it\n}","preventionTips":["Prefer non-throwing Get/TryGetValue unless absence is truly a bug.","Ensure keys are set (or have defaults) during object construction before reads.","Use the same PropertyKey instance everywhere rather than re-creating keys."],"tags":["argument-exception","property-key","property-container","missing-value"],"backgroundTag":"record-not-found","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"}