{"record":{"id":"0443343285d1df2c","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-targetobject","errorCode":null,"errorMessage":"ArgumentNullException(nameof(targetObject))","messagePattern":"ArgumentNullException\\(nameof\\(targetObject\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs","lineNumber":277,"sourceCode":"        {\n            ArgumentNullException.ThrowIfNull(targetObject);\n            ArgumentNullException.ThrowIfNull(eventArgs);\n\n            Condition condition = targetObject as Condition;\n            if (condition != null && eventArgs.Member.Name == \"Binding\" && eventArgs.MarkupExtension is BindingBase)\n            {\n                condition.Binding = eventArgs.MarkupExtension as BindingBase;\n\n                eventArgs.Handled = true;\n            }\n        }\n\n        public static void ReceiveTypeConverter(object targetObject, XamlSetTypeConverterEventArgs eventArgs)\n        {\n            Condition condition = targetObject as Condition;\n            if (condition == null)\n            {\n                throw new ArgumentNullException(nameof(targetObject));\n            }\n            ArgumentNullException.ThrowIfNull(eventArgs);\n\n            if (eventArgs.Member.Name == \"Property\")\n            {\n                condition._unresolvedProperty = eventArgs.Value;\n                condition._serviceProvider = eventArgs.ServiceProvider;\n                condition._cultureInfoForTypeConverter = eventArgs.CultureInfo;\n\n                eventArgs.Handled = true;\n            }\n            else if (eventArgs.Member.Name == \"Value\")\n            {\n                condition._unresolvedValue = eventArgs.Value;\n                condition._serviceProvider = eventArgs.ServiceProvider;\n                condition._cultureInfoForTypeConverter = eventArgs.CultureInfo;\n\n                eventArgs.Handled = true;","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs#L259-L295","documentation":"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.","triggerScenarios":"XAML set-type-converter event wiring passing null for targetObject, e.g. misconfigured XamlSetTypeConverterAttribute usage or reflective invocation with a null target.","commonSituations":"Custom XAML schema contexts or markup-extension tooling calling ReceiveTypeConverter directly with the wrong arguments; deserialization edge cases in designer tooling.","solutions":["Ensure the XAML object graph instantiates a Condition before the type-converter callback fires.","When calling directly, pass the actual Condition instance as targetObject.","Check eventArgs is non-null too, since it is validated immediately afterwards."],"exampleFix":"// before\nCondition.ReceiveTypeConverter(null, eventArgs);\n// after\nCondition.ReceiveTypeConverter(conditionInstance, eventArgs);","handlingStrategy":"type-guard","validationCode":"if (targetObject is not Condition)\n    throw new ArgumentException(nameof(targetObject), \"Expected a Condition instance\");","typeGuard":"bool IsConditionTarget(object o) => o is Condition;","tryCatchPattern":"try { Condition.ReceiveTypeConverter(target, args); }\ncatch (ArgumentNullException ex) { /* pass a real Condition as targetObject */ }","preventionTips":["Only invoke via the XAML infrastructure on a Condition object graph.","Null-check targetObject before calling the static callback directly.","Keep the XamlSetTypeConverter wiring attached to the Condition type."],"tags":["wpf","xaml","null-argument"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}