dotnet/wpf · error · ArgumentNullException

ArgumentNullException(nameof(targetObject))

Error message

ArgumentNullException(nameof(targetObject))

What it means

ReceiveTypeConverter is a XAML callback invoked by the XAML type-converter infrastructure; the targetObject must be a Condition. A null targetObject (or one that is not a Condition) throws ArgumentNullException because the callback cannot operate without a valid target.

Solutions

  1. Ensure the XAML object graph instantiates a Condition before the type-converter callback fires.
  2. When calling directly, pass the actual Condition instance as targetObject.
  3. Check eventArgs is non-null too, since it is validated immediately afterwards.

Example fix

// before
Condition.ReceiveTypeConverter(null, eventArgs);
// after
Condition.ReceiveTypeConverter(conditionInstance, eventArgs);
Defensive patterns

Strategy: type-guard

Validate before calling

if (targetObject is not Condition)
    throw new ArgumentException(nameof(targetObject), "Expected a Condition instance");

Type guard

bool IsConditionTarget(object o) => o is Condition;

Try / catch

try { Condition.ReceiveTypeConverter(target, args); }
catch (ArgumentNullException ex) { /* pass a real Condition as targetObject */ }

Prevention

When it happens

Trigger: XAML set-type-converter event wiring passing null for targetObject, e.g. misconfigured XamlSetTypeConverterAttribute usage or reflective invocation with a null target.

Common situations: Custom XAML schema contexts or markup-extension tooling calling ReceiveTypeConverter directly with the wrong arguments; deserialization edge cases in designer tooling.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/0443343285d1df2c. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs:277

        {
            ArgumentNullException.ThrowIfNull(targetObject);
            ArgumentNullException.ThrowIfNull(eventArgs);

            Condition condition = targetObject as Condition;
            if (condition != null && eventArgs.Member.Name == "Binding" && eventArgs.MarkupExtension is BindingBase)
            {
                condition.Binding = eventArgs.MarkupExtension as BindingBase;

                eventArgs.Handled = true;
            }
        }

        public static void ReceiveTypeConverter(object targetObject, XamlSetTypeConverterEventArgs eventArgs)
        {
            Condition condition = targetObject as Condition;
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(targetObject));
            }
            ArgumentNullException.ThrowIfNull(eventArgs);

            if (eventArgs.Member.Name == "Property")
            {
                condition._unresolvedProperty = eventArgs.Value;
                condition._serviceProvider = eventArgs.ServiceProvider;
                condition._cultureInfoForTypeConverter = eventArgs.CultureInfo;

                eventArgs.Handled = true;
            }
            else if (eventArgs.Member.Name == "Value")
            {
                condition._unresolvedValue = eventArgs.Value;
                condition._serviceProvider = eventArgs.ServiceProvider;
                condition._cultureInfoForTypeConverter = eventArgs.CultureInfo;

                eventArgs.Handled = true;

View on GitHub (pinned to 81131a70a4)