{"record":{"id":"ef55d6d4bacb5555","repo":"dotnet/wpf","slug":"sr-format-sr-valueinarrayisnull-types","errorCode":null,"errorMessage":"SR.Format(SR.ValueInArrayIsNull, \"types\")","messagePattern":"SR\\.Format\\(SR\\.ValueInArrayIsNull, \"types\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ServiceProviderContext.cs","lineNumber":155,"sourceCode":"                {\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            }\n\n            return _xamlContext.ServiceProvider_GetFirstAmbientValue(types);\n        }\n\n        IEnumerable<AmbientPropertyValue> IAmbientProvider.GetAllAmbientValues(\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\"));","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ServiceProviderContext.cs#L137-L173","documentation":"GetFirstAmbientValue validates that no entry in the 'types' array is null before delegating to the inner context. A null XamlType element throws ArgumentException with ValueInArrayIsNull naming 'types'.","triggerScenarios":"Calling IAmbientProvider.GetFirstAmbientValue(types) where the types array contains a null element, e.g. GetFirstAmbientValue(new XamlType[] { schemaContext.GetType(typeof(Grid)), null }).","commonSituations":"Populating ceiling types from SchemaContext.GetType(typeof(T)) calls that returned null for unregistered or renamed types; arrays assembled from config or reflection data with missing entries.","solutions":["Filter null entries: types.Where(t => t != null).ToArray() before the call.","Verify each SchemaContext.GetType/GetXamlType result for null before adding it to the array.","Throw or log a specific message when a type fails to resolve so the bad source is identified.","Catch ArgumentException to surface which ceiling-type list was malformed."],"exampleFix":"// before\nvar ceiling = new[] { sxCtx.GetType(typeof(Grid)), sxCtx.GetType(typeof(Unknown)) };\nvar v = ambient.GetFirstAmbientValue(ceiling); // throws if second is null\n// after\nvar ceiling = new[] { sxCtx.GetType(typeof(Grid)), sxCtx.GetType(typeof(Unknown)) }\n    .Where(t => t != null).ToArray();\nvar v = ambient.GetFirstAmbientValue(ceiling);","handlingStrategy":"validation","validationCode":"if (types.Any(t => t == null)) throw new ArgumentException(\"types contains null entries\", nameof(types));","typeGuard":"XamlType[] NonNull(XamlType[] src) => src.Where(t => t != null).ToArray();","tryCatchPattern":"try { return ambient.GetFirstAmbientValue(types); }\ncatch (ArgumentException ex) { // null type entry\n  throw new ArgumentException(\"Bad ceiling types array\", ex); }","preventionTips":["Verify SchemaContext.GetType results before adding","Keep ceiling-type lists statically defined where possible","Centralize type resolution with null checks"],"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"}