unoplatform/uno · error · ArgumentNullException

descriptor

Error message

descriptor

What it means

Thrown by ValueSerializer.GetSerializerFor(PropertyDescriptor, IValueSerializerContext) when the descriptor argument is null. The descriptor is used to obtain the TypeConverter and to delegate to the context, so it must be present.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Windows.Markup/ValueSerializer.cs:53

	// [System.Runtime.CompilerServices.TypeForwardedFrom (Consts.AssemblyWindowsBase)]
	public abstract class ValueSerializer
	{
		public static ValueSerializer GetSerializerFor (PropertyDescriptor descriptor)
		{
			return GetSerializerFor (descriptor, null);
		}

		public static ValueSerializer GetSerializerFor (Type type)
		{
			return GetSerializerFor (type, null);
		}

		// untested
		public static ValueSerializer GetSerializerFor (PropertyDescriptor descriptor, IValueSerializerContext context)
		{
			if (descriptor == null)
			{
				throw new ArgumentNullException ("descriptor");
			}

			if (context != null)
			{
				return context.GetValueSerializerFor (descriptor);
			}

			var tc = descriptor.Converter;
			if (tc != null && tc.GetType () != typeof (TypeConverter))
			{
				return new TypeConverterValueSerializer (tc);
			}

			return null;
		}

		public static ValueSerializer GetSerializerFor (Type type, IValueSerializerContext context)
		{

View on GitHub (pinned to 0418340488)

Solutions

  1. Obtain the PropertyDescriptor via a non-failing lookup (e.g. TypeDescriptor.GetProperties(type)[name]) and verify non-null before calling.
  2. Use the GetSerializerFor(Type, context) overload when only a type is available.
  3. Null-check the descriptor at the call site and handle the missing case explicitly.

Example fix

// before
var desc = TypeDescriptor.GetProperties(obj)["BadName"];
var ser = ValueSerializer.GetSerializerFor(desc, ctx); // throws

// after
var desc = TypeDescriptor.GetProperties(obj)["RealName"];
if (desc != null)
    var ser = ValueSerializer.GetSerializerFor(desc, ctx);
Defensive patterns

Strategy: validation

Validate before calling

var desc = TypeDescriptor.GetProperties(obj)[memberName];
if (desc == null)
    throw new InvalidOperationException($"No descriptor for {memberName}");
var ser = ValueSerializer.GetSerializerFor(desc, ctx);

Type guard

static bool HasDescriptor(PropertyDescriptor d) => d != null;

Prevention

When it happens

Trigger: Calling GetSerializerFor((PropertyDescriptor)null, context), typically from a custom XAML serialization pipeline that passed a descriptor obtained from a failed TypeDescriptor.GetDescriptor lookup.

Common situations: Custom serializers that obtain PropertyDescriptor dynamically and do not null-check; serialization of members without an associated descriptor; reflection-based binding failures.

Related errors


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