{"record":{"id":"a277d9356eb6b06b","repo":"stride3d/stride","slug":"the-object-passed-to-this-value-converter-is-not-a-type","errorCode":null,"errorMessage":"The object passed to this value converter is not a type.","messagePattern":"The object passed to this value converter is not a type\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/UnderlyingType.cs","lineNumber":21,"sourceCode":"using System;\nusing System.Globalization;\nusing Stride.Core.Annotations;\n\nnamespace Stride.Core.Presentation.ValueConverters\n{\n    /// <summary>\n    /// This converter convert a <see cref=\"Nullable\"/> type to its underlying type. If the type is not nullable, it returns the type itself.\n    /// </summary>\n    public class UnderlyingType : OneWayValueConverter<UnderlyingType>\n    {\n        /// <inheritdoc/>\n        [NotNull]\n        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)\n        {\n            var type = value as Type;\n            if (type == null)\n            {\n                throw new ArgumentException(\"The object passed to this value converter is not a type.\");\n            }\n            return Nullable.GetUnderlyingType(type) ?? value;\n        }\n    }\n}\n","sourceCodeStart":3,"sourceCodeEnd":27,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/UnderlyingType.cs#L3-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar r = converter.Convert(\"Int32\", typeof(Type), null, culture); // throws (string, not Type)\n// after\nvar r = converter.Convert(typeof(int?), typeof(Type), null, culture); // returns typeof(int)","handlingStrategy":"type-guard","validationCode":"bool ok = value is System.Type;","typeGuard":"static bool IsType(object v) => v is System.Type;","tryCatchPattern":"try { return converter.Convert(value, typeof(Type), null, culture); }\ncatch (ArgumentException) { return value; }","preventionTips":["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."],"tags":["wpf","valueconverter","reflection","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}