{"record":{"id":"acd7cf18b85d7142","repo":"dotnet/wpf","slug":"sr-argumentrequired","errorCode":null,"errorMessage":"SR.ArgumentRequired","messagePattern":"SR\\.ArgumentRequired","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlValueConverter.cs","lineNumber":33,"sourceCode":"        private TConverterBase _instance;\n        private ThreeValuedBool _isPublic;\n\n        private volatile bool _instanceIsSet; // volatile for the same reason as valid flags in TypeReflector/MemberReflector\n\n        public string Name { get; }\n        public Type ConverterType { get; }\n        public XamlType TargetType { get; }\n\n        public XamlValueConverter(Type converterType, XamlType targetType)\n            :this(converterType, targetType, null)\n        {\n        }\n\n        public XamlValueConverter(Type converterType, XamlType targetType, string name)\n        {\n            if (converterType is null && targetType is null && name is null)\n            {\n                throw new ArgumentException(SR.Format(SR.ArgumentRequired, $\"{nameof(converterType)}, {nameof(targetType)}, {nameof(name)}\"));\n            }\n\n            ConverterType = converterType;\n            TargetType = targetType;\n            Name = name ?? GetDefaultName();\n        }\n\n        public TConverterBase ConverterInstance\n        {\n            get\n            {\n                if (!_instanceIsSet)\n                {\n                    Interlocked.CompareExchange(ref _instance, CreateInstance(), null);\n                    _instanceIsSet = true;\n                }\n\n                return _instance;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlValueConverter.cs#L15-L51","documentation":"The XamlValueConverter(Type, XamlType, name) constructor throws ArgumentException('ArgumentRequired') when all three parameters are null. A value converter must be identifiable by at least one of: its converter CLR type, its target XamlType, or an explicit name — otherwise instances could not be named, cached, or compared (IEquatable). At least one identifier is therefore mandatory.","triggerScenarios":"new XamlValueConverter<TConverterBase>(null, null, null) — e.g. code that conditionally builds converters where every input defaulted to null, or deserialization/constructor plumbing that forgot to pass the converter type or target type.","commonSituations":"Generic converter-factory code where a config-driven converterType lookup returned null and fallbacks (targetType, name) were also null; refactoring that made previously-supplied arguments optional; unit tests constructing a 'blank' converter.","solutions":["Pass at least one non-null argument — typically the converter Type or the target XamlType.","Provide a name when neither type nor target applies so the converter can still be identified.","Guard the construction site: validate that at least one argument is non-null before constructing.","Catch ArgumentException at the boundary if inputs come from external configuration and surface a clear config error."],"exampleFix":"// before\nvar conv = new XamlValueConverter<ValueConverter>(maybeType, maybeTarget, null);\n// after\nif (maybeType is null && maybeTarget is null) throw new InvalidOperationException(\"converter requires a type or target\");\nvar conv = new XamlValueConverter<ValueConverter>(maybeType, maybeTarget, null);","handlingStrategy":"validation","validationCode":"if (converterType is null && targetType is null && name is null) throw new ArgumentException(\"At least one of converterType/targetType/name is required\");","typeGuard":"static bool ConverterIdentifiable(Type t, XamlType target, string name) => t is not null || target is not null || name is not null;","tryCatchPattern":"try { var c = new XamlValueConverter<T>(type, target, name); } catch (ArgumentException ex) { /* all-null converter descriptor */ }","preventionTips":["Always pass the converter Type or target XamlType when constructing converters.","Validate configuration-driven converter inputs before construction.","Supply an explicit name for converter identification when types are unknown.","Centralize converter construction in one factory that enforces this invariant."],"tags":["xaml","argumentexception","null-argument","converter"],"backgroundTag":"missing-required-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"}