dotnet/wpf · error · ArgumentException
SR.Format(SR.ValueInArrayIsNull, "properties")
Error message
SR.Format(SR.ValueInArrayIsNull, "properties")
What it means
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'.
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.
Example fix
// before
var props = new[] { tagType.GetMember("Width"), tagType.GetMember("NoSuchProp") };
var value = ambientProvider.GetFirstAmbientValue(null, props); // throws
// after
var props = new[] { tagType.GetMember("Width"), tagType.GetMember("NoSuchProp") }
.Where(p => p != null).ToArray();
var value = ambientProvider.GetFirstAmbientValue(null, props); Defensive patterns
Strategy: validation
Validate before calling
if (properties.Any(p => p == null)) throw new ArgumentException("properties contains null members", nameof(properties)); Type guard
XamlMember[] NonNull(XamlMember[] src) => src.Where(p => p != null).ToArray();
Try / catch
try { return ambient.GetFirstAmbientValue(ceiling, props); }
catch (ArgumentException ex) { // null member in array — log props and rethrow
throw new ArgumentException("Bad properties array", ex); } Prevention
- Filter arrays with .Where(p => p != null) before ambient queries
- Check GetMember return values immediately
- Build member lists in one validated helper method
When it happens
Trigger: Calling ServiceProvider_GetFirstAmbientValue/IAmbientProvider.GetFirstAmbientValue(ceilingTypes, properties) where the properties array contains a null element, e.g. GetFirstAmbientValue(null, new[] { someType.GetMember("Prop"), null }).
Common situations: 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.
Related errors
- SR.Format(SR.ValueInArrayIsNull, "types")
- ArgumentNullException(name)
- nameof(declaringType)
- SR.SimpleFixupsMustHaveOneName
- SR.Verify_NeitherNullNorEmpty
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/15e23191906cdacd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ServiceProviderContext.cs:139
{
get { return _xamlContext.BaseUri; }
set { throw new InvalidOperationException(SR.MustNotCallSetter); }
}
#endregion
#region IAmbientProvider Members
AmbientPropertyValue IAmbientProvider.GetFirstAmbientValue(
IEnumerable<XamlType> ceilingTypes,
params XamlMember[] properties)
{
ArgumentNullException.ThrowIfNull(properties);
foreach (var property in properties)
{
if (property is null)
{
// we don't allow any property to be null
throw new ArgumentException(SR.Format(SR.ValueInArrayIsNull, "properties"));
}
}
return _xamlContext.ServiceProvider_GetFirstAmbientValue(ceilingTypes, properties);
}
object IAmbientProvider.GetFirstAmbientValue(params XamlType[] types)
{
ArgumentNullException.ThrowIfNull(types);
foreach (var type in types)
{
if (type is null)
{
// we don't allow any type to be null
throw new ArgumentException(SR.Format(SR.ValueInArrayIsNull, "types"));
}
}View on GitHub (pinned to 81131a70a4)