dotnet/wpf · error · ArgumentException
SR.Format(SR.ValueInArrayIsNull, "types")
Error message
SR.Format(SR.ValueInArrayIsNull, "types")
What it means
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'.
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.
Example fix
// before
var ceiling = new[] { sxCtx.GetType(typeof(Grid)), sxCtx.GetType(typeof(Unknown)) };
var v = ambient.GetFirstAmbientValue(ceiling); // throws if second is null
// after
var ceiling = new[] { sxCtx.GetType(typeof(Grid)), sxCtx.GetType(typeof(Unknown)) }
.Where(t => t != null).ToArray();
var v = ambient.GetFirstAmbientValue(ceiling); Defensive patterns
Strategy: validation
Validate before calling
if (types.Any(t => t == null)) throw new ArgumentException("types contains null entries", nameof(types)); Type guard
XamlType[] NonNull(XamlType[] src) => src.Where(t => t != null).ToArray();
Try / catch
try { return ambient.GetFirstAmbientValue(types); }
catch (ArgumentException ex) { // null type entry
throw new ArgumentException("Bad ceiling types array", ex); } Prevention
- Verify SchemaContext.GetType results before adding
- Keep ceiling-type lists statically defined where possible
- Centralize type resolution with null checks
When it happens
Trigger: Calling IAmbientProvider.GetFirstAmbientValue(types) where the types array contains a null element, e.g. GetFirstAmbientValue(new XamlType[] { schemaContext.GetType(typeof(Grid)), null }).
Common situations: 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.
Related errors
- SR.Format(SR.ValueInArrayIsNull, "properties")
- ArgumentNullException(name)
- nameof(declaringType)
- SR.SimpleFixupsMustHaveOneName
- SR.Verify_NeitherNullNorEmpty
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ef55d6d4bacb5555.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ServiceProviderContext.cs:155
{
// 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"));
}
}
return _xamlContext.ServiceProvider_GetFirstAmbientValue(types);
}
IEnumerable<AmbientPropertyValue> IAmbientProvider.GetAllAmbientValues(
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"));View on GitHub (pinned to 81131a70a4)