{"record":{"id":"7229b8d52dc71b97","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-value-typeextension","errorCode":null,"errorMessage":"ArgumentNullException(nameof(value))","messagePattern":"ArgumentNullException\\(nameof\\(value\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs","lineNumber":95,"sourceCode":"            {\n                throw new InvalidOperationException(SR.Format(SR.MarkupExtensionTypeNameBad, _typeName));\n            }\n\n            return _type;\n        }\n\n        /// <summary>\n        /// The typename represented by this markup extension. The name has the format\n        /// Prefix:Typename, where Prefix is the xml namespace prefix for this type.\n        /// </summary>\n        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]\n        public string TypeName\n        {\n            get => _typeName;\n            set\n            {\n                // Reset the type so ProvideValue does not use the existing type.\n                _typeName = value ?? throw new ArgumentNullException(nameof(value));\n                _type = null;\n            }\n        }\n\n        /// <summary>\n        /// The type represented by this markup extension.\n        /// </summary>\n        [DefaultValue(null)]\n        [ConstructorArgument(\"type\")]\n        public Type Type\n        {\n            get => _type;\n            set\n            {\n                // Reset the type name so ProvideValue does not use the existing type name.\n                _type = value ?? throw new ArgumentNullException(nameof(value));\n                _typeName = null;\n            }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/TypeExtension.cs#L77-L113","documentation":"The TypeExtension.TypeName setter throws ArgumentNullException when assigned null. Assigning TypeName is meant to switch the extension to name-based resolution; null would leave the extension in an inconsistent state, so the library rejects it.","triggerScenarios":"Executing typeExtension.TypeName = null; on any TypeExtension instance.","commonSituations":"Code that clears markup-extension settings in bulk with null values; reflection-based serializers or designers assigning null for an absent attribute value.","solutions":["Assign a non-null string, or create a new TypeExtension instance instead of nulling properties.","Guard: if (value != null) ext.TypeName = value;","Use the Type property with a real Type when the name is unknown.","Wrap in try/catch ArgumentNullException if null assignment is possible in legacy code paths."],"exampleFix":"// before\next.TypeName = GetTypeName() ; // GetTypeName() may return null\n// after\nvar name = GetTypeName();\nif (name != null) ext.TypeName = name;","handlingStrategy":"type-guard","validationCode":"if (name is null) throw new ArgumentException(\"TypeName cannot be null.\");\next.TypeName = name;","typeGuard":"static bool IsNonEmpty(string? s) => !string.IsNullOrEmpty(s);","tryCatchPattern":"try { ext.TypeName = value; }\ncatch (ArgumentNullException) { ext.TypeName = string.Empty; log.Warn(\"Null TypeName ignored.\"); }","preventionTips":["Never reset markup-extension properties to null; recreate the instance instead.","Enable nullable reference types so null assignments surface at compile time."],"tags":["xaml","wpf","null-argument","property-setter"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}