unoplatform/uno · error · ArgumentException

Either of converterType, targetType or name must be non-null

Error message

Either of converterType, targetType or name must be non-null

What it means

Thrown by the XamlValueConverter<TConverterBase> constructor when all three of converterType, targetType, and name are null. XamlValueConverter needs at least one non-null identity component to be meaningful (it represents a value converter keyed by converter type, target type, and/or a display name); an all-null instance is degenerate and is rejected.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlValueConverter.cs:44

using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace Uno.Xaml.Schema
{
	public class XamlValueConverter<[DynamicallyAccessedMembers(TConverterBaseRequirements)] TConverterBase> : IEquatable<XamlValueConverter<TConverterBase>>
		where TConverterBase : class
	{
		internal const DynamicallyAccessedMemberTypes TConverterBaseRequirements = DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors;

		public XamlValueConverter ([DynamicallyAccessedMembers(TConverterBaseRequirements)] Type converterType, XamlType targetType)
			: this (converterType, targetType, null)
		{
		}

		public XamlValueConverter ([DynamicallyAccessedMembers(TConverterBaseRequirements)] Type converterType, XamlType targetType, string name)
		{
			if (converterType == null && targetType == null && name == null)
				throw new ArgumentException ("Either of converterType, targetType or name must be non-null");
			ConverterType = converterType;
			TargetType = targetType;
			Name = name;
		}

		TConverterBase converter_instance;
		public TConverterBase ConverterInstance {
			get {
				if (converter_instance == null)
					converter_instance = CreateInstance ();
				return converter_instance;
			}
		}
		[DynamicallyAccessedMembers(TConverterBaseRequirements)]
		public Type ConverterType { get; private set; }
		public string Name { get; private set; }
		public XamlType TargetType { get; private set; }

View on GitHub (pinned to 0418340488)

Solutions

  1. Ensure at least one of converterType, targetType, or name is non-null when constructing XamlValueConverter.
  2. Fix upstream resolution logic: if you expected a converter type from a TypeConverterAttribute, verify the attribute was present and resolved.
  3. Return null from your lookup function instead of constructing a degenerate XamlValueConverter when nothing resolves.

Example fix

// before
var vc = new XamlValueConverter<TypeConverter>(resolvedConverterType, resolvedTargetType, name);
// all three resolved null

// after
if (resolvedConverterType == null && resolvedTargetType == null && name == null)
    return null; // no converter applicable
var vc = new XamlValueConverter<TypeConverter>(resolvedConverterType, resolvedTargetType, name);
Defensive patterns

Strategy: validation

Validate before calling

if (converterType == null && targetType == null && string.IsNullOrEmpty(name))
    return null; // no converter applicable
var vc = new XamlValueConverter<TypeConverter>(converterType, targetType, name);

Type guard

static bool HasIdentity(Type ct, XamlType tt, string n)
    => ct != null || tt != null || !string.IsNullOrEmpty(n);

Try / catch

try { return new XamlValueConverter<T>(ct, tt, name); }
catch (ArgumentException) { return null; }

Prevention

When it happens

Trigger: Constructing new XamlValueConverter<TypeConverter>(null, null, null). Or calling the two-argument overload new XamlValueConverter<T>(null, null) which forwards name=null, hitting the same guard.

Common situations: Schema-building code that resolves a value converter from metadata where all three fields were unresolved (e.g. a TypeConverterAttribute and TargetType both missing from a reflected member). Reflection-driven XAML schema context construction with incomplete type info.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/05d0d7cf7bfbeade. Report an issue: GitHub.