{"record":{"id":"15e23191906cdacd","repo":"dotnet/wpf","slug":"sr-format-sr-valueinarrayisnull-properties","errorCode":null,"errorMessage":"SR.Format(SR.ValueInArrayIsNull, \"properties\")","messagePattern":"SR\\.Format\\(SR\\.ValueInArrayIsNull, \"properties\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ServiceProviderContext.cs","lineNumber":139,"sourceCode":"        {\n            get { return _xamlContext.BaseUri; }\n            set { throw new InvalidOperationException(SR.MustNotCallSetter); }\n        }\n        #endregion\n\n        #region IAmbientProvider Members\n        AmbientPropertyValue IAmbientProvider.GetFirstAmbientValue(\n                                                    IEnumerable<XamlType> ceilingTypes,\n                                                    params XamlMember[] properties)\n        {\n            ArgumentNullException.ThrowIfNull(properties);\n\n            foreach (var property in properties)\n            {\n                if (property is null)\n                {\n                    // we don't allow any property to be null\n                    throw new ArgumentException(SR.Format(SR.ValueInArrayIsNull, \"properties\"));\n                }\n            }\n\n            return _xamlContext.ServiceProvider_GetFirstAmbientValue(ceilingTypes, properties);\n        }\n\n        object IAmbientProvider.GetFirstAmbientValue(params XamlType[] types)\n        {\n            ArgumentNullException.ThrowIfNull(types);\n\n            foreach (var type in types)\n            {\n                if (type is null)\n                {\n                    // we don't allow any type to be null\n                    throw new ArgumentException(SR.Format(SR.ValueInArrayIsNull, \"types\"));\n                }\n            }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ServiceProviderContext.cs#L121-L157","documentation":"IAmbientProvider.GetFirstAmbientValue validates that no entry in the 'properties' array is null before delegating to the inner XamlContext. Passing a null XamlMember in the properties collection throws ArgumentException with the ValueInArrayIsNull message naming 'properties'.","triggerScenarios":"Calling ServiceProvider_GetFirstAmbientValue/IAmbientProvider.GetFirstAmbientValue(ceilingTypes, properties) where the properties array contains a null element, e.g. GetFirstAmbientValue(null, new[] { someType.GetMember(\"Prop\"), null }).","commonSituations":"Building the member list dynamically from lookups that can return null (GetMember on a missing property) and passing the array straight through; collection-initializer typos; data-driven ambient value queries.","solutions":["Filter or reject null entries before calling: properties.Where(p => p != null).ToArray().","Check that each XamlType.GetMember(...) call succeeded (return value not null) when building the array.","Guard with a validation loop and throw a clearer exception identifying which lookup failed.","Catch ArgumentException and report the offending index to the caller for diagnosis."],"exampleFix":"// before\nvar props = new[] { tagType.GetMember(\"Width\"), tagType.GetMember(\"NoSuchProp\") };\nvar value = ambientProvider.GetFirstAmbientValue(null, props); // throws\n// after\nvar props = new[] { tagType.GetMember(\"Width\"), tagType.GetMember(\"NoSuchProp\") }\n    .Where(p => p != null).ToArray();\nvar value = ambientProvider.GetFirstAmbientValue(null, props);","handlingStrategy":"validation","validationCode":"if (properties.Any(p => p == null)) throw new ArgumentException(\"properties contains null members\", nameof(properties));","typeGuard":"XamlMember[] NonNull(XamlMember[] src) => src.Where(p => p != null).ToArray();","tryCatchPattern":"try { return ambient.GetFirstAmbientValue(ceiling, props); }\ncatch (ArgumentException ex) { // null member in array — log props and rethrow\n  throw new ArgumentException(\"Bad properties array\", ex); }","preventionTips":["Filter arrays with .Where(p => p != null) before ambient queries","Check GetMember return values immediately","Build member lists in one validated helper method"],"tags":["system-xaml","argument-validation","null-argument","ambient-provider"],"backgroundTag":"null-argument","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"}