stride3d/stride · error · ArgumentException
The object passed to this value converter is not a type.
Error message
The object passed to this value converter is not a type.
What it means
UnderlyingTypeConverter resolves the underlying type of a Nullable<T>: given typeof(int?) it returns typeof(int); given a non-nullable Type it returns the value unchanged. It throws this ArgumentException from Convert (UnderlyingType.cs:21) when the bound value is not a System.Type instance at all.
Solutions
- Bind a value that is a System.Type (e.g. `Binding Path="."` on a Type-typed source or `{x:Type SomeType}`).
- If you have a type name string, resolve it first with Type.GetType(name) before passing it.
- For object instances, use `{Binding Source={x:Type local:MyType}}` or bind the instance's GetType() result.
- Guard with `value is Type` before calling Convert, or wrap the converter to pass through non-Type values.
Example fix
// before
var r = converter.Convert("Int32", typeof(Type), null, culture); // throws (string, not Type)
// after
var r = converter.Convert(typeof(int?), typeof(Type), null, culture); // returns typeof(int) Defensive patterns
Strategy: type-guard
Validate before calling
bool ok = value is System.Type;
Type guard
static bool IsType(object v) => v is System.Type;
Try / catch
try { return converter.Convert(value, typeof(Type), null, culture); }
catch (ArgumentException) { return value; } Prevention
- Feed the converter with {x:Type ...} markup extensions or Type-typed properties, not type-name strings.
- Resolve name strings with Type.GetType before binding if only names are available.
- Remember non-nullable Types pass through unchanged; the error is only for non-Type inputs.
When it happens
Trigger: Binding a non-Type value into this converter — e.g. binding an object instance instead of its type, a type name string, or null — then calling Convert; also direct calls passing arbitrary objects.
Common situations: Binding to a property like `GetType()` incorrectly, passing the type's FullName string instead of the Type, binding a generic collection item while expecting the item's type, tests using dummy values.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- is not a numeric type
- The parameter of the ConvertBack method of this converter…
- The value of the ConvertBack method of this converter must…
- The parameter of the ConvertBack method of this converter…
- The value of the ConvertBack method of this converter must…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/a277d9356eb6b06b.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/UnderlyingType.cs:21
using System;
using System.Globalization;
using Stride.Core.Annotations;
namespace Stride.Core.Presentation.ValueConverters
{
/// <summary>
/// This converter convert a <see cref="Nullable"/> type to its underlying type. If the type is not nullable, it returns the type itself.
/// </summary>
public class UnderlyingType : OneWayValueConverter<UnderlyingType>
{
/// <inheritdoc/>
[NotNull]
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var type = value as Type;
if (type == null)
{
throw new ArgumentException("The object passed to this value converter is not a type.");
}
return Nullable.GetUnderlyingType(type) ?? value;
}
}
}
View on GitHub (pinned to 96fad776d2)