{"record":{"id":"5b895f56118fd6d8","repo":"dotnet/wpf","slug":"sr-format-sr-notambientproperty-xamlmember-declaringtype","errorCode":null,"errorMessage":"SR.Format(SR.NotAmbientProperty, xamlMember.DeclaringType.Name, xamlMember.Name)","messagePattern":"SR\\.Format\\(SR\\.NotAmbientProperty, xamlMember\\.DeclaringType\\.Name, xamlMember\\.Name\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs","lineNumber":317,"sourceCode":"            if (frame.Member == XamlLanguage.Initialization)\n            {\n                return frame.XamlType;\n            }\n\n            return frame.Member.Type;\n        }\n\n        private List<AmbientPropertyValue> FindAmbientValues(IEnumerable<XamlType> ceilingTypesEnumerable,\n                                                             bool searchLiveStackOnly,\n                                                             IEnumerable<XamlType> types,\n                                                             XamlMember[] properties,\n                                                             bool stopAfterFirst)\n        {\n            foreach (XamlMember xamlMember in properties)\n            {\n                if (!xamlMember.IsAmbient)\n                {\n                    throw new ArgumentException(SR.Format(SR.NotAmbientProperty, xamlMember.DeclaringType.Name, xamlMember.Name), nameof(properties));\n                }\n            }\n\n            List<XamlType> ceilingTypes = ceilingTypesEnumerable is not null ? new List<XamlType>(ceilingTypesEnumerable) : null;\n\n            List<AmbientPropertyValue> retList = new List<AmbientPropertyValue>();\n\n            // Start the search for ambient properties and types starting with the parent frame.\n            ObjectWriterFrame frame = _stack.PreviousFrame;\n            ObjectWriterFrame lowerFrame = _stack.CurrentFrame;\n\n            while (frame.Depth >= 1)\n            {\n                if (searchLiveStackOnly && frame.Depth <= SavedDepth)\n                {\n                    break;\n                }\n","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs#L299-L335","documentation":"ObjectWriterContext.FindAmbientValues validates that every XamlMember passed in the properties collection has IsAmbient set. When a non-ambient property is supplied it throws ArgumentException with SR.NotAmbientProperty, naming the declaring type and member, with paramName \"properties\".","triggerScenarios":"Calling the API that collects ambient values (e.g. via IAmbientProvider / XamlObjectWriter internals or custom schema context code) and passing a XamlMember in the properties array whose SchemaContext does not mark it ambient.","commonSituations":"Custom XAML schema contexts or ambient-property lookups where the ambient attribute ([Ambient]) is missing from the property definition; properties enumerated from the wrong type so IsAmbient is false; hand-built XamlMember lists mixing ambient and regular members.","solutions":["Add [Ambient] (System.Xaml.Schema.AmbientAttribute) to the property so IsAmbient returns true, or mark it ambient in your custom schema context.","Filter the properties list before calling: only include members where xamlMember.IsAmbient is true.","Ensure you are using the correct SchemaContext instance so ambient metadata is detected as intended."],"exampleFix":"// before\nvar props = new[] { schemaContext.GetXamlType(typeof(Panel)).GetMember(\"Children\"), xt.GetMember(\"Tag\") }; // Tag is not ambient\n// after\nvar props = new[] { schemaContext.GetXamlType(typeof(Panel)).GetMember(\"Children\") }\n    .Where(m => m.IsAmbient).ToArray();","handlingStrategy":"validation","validationCode":"if (properties.Any(m => !m.IsAmbient))\n    throw new ArgumentException(\"All members must be ambient\", nameof(properties));","typeGuard":"static bool AllAmbient(IEnumerable<XamlMember> members) => members.All(m => m.IsAmbient);","tryCatchPattern":"try { FindAmbientValues(properties, ceilingTypes, stopAfterFirst); }\ncatch (ArgumentException ex) when (ex.ParamName == \"properties\")\n{ /* filter out non-ambient members and retry */ }","preventionTips":["Decorate ambient properties with [Ambient] so IsAmbient is true.","Filter with .Where(m => m.IsAmbient) before any ambient-lookup API call.","Do not mix regular members into ambient member lists."],"tags":["wpf","xaml","ambient-properties","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}