{"record":{"id":"2e46c58b369d95dd","repo":"dotnet/wpf","slug":"the-translator-argument-cannot-be-null","errorCode":null,"errorMessage":"The translator argument cannot be null.","messagePattern":"The translator argument cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMap.cs","lineNumber":86,"sourceCode":"                ThrowIfPropertyDoesntExistOnSource(propertyName);\n                PropertyTranslator value;\n                if (_wrappedDictionary.TryGetValue(propertyName, out value))\n                {\n                    return value;\n                }\n                return null;\n            }\n            set\n            {\n                //Run through our regular invalid property checks, then\n                //apply the translator\n                if (string.IsNullOrEmpty(propertyName))\n                {\n                    throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, \"propertyName\"));\n                }\n                if (value == null)\n                {\n                    throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, \"translator\"));\n                }\n                ThrowIfPropertyDoesntExistOnSource(propertyName);\n                _wrappedDictionary[propertyName] = value;    //This will replace an existing mapping, unlike Add.\n                Apply(propertyName);\n            }\n        }\n\n        /// <summary>\n        ///     Returns an ICollection of strings identifying all of the host control \n        ///     properties that have been mapped.  \n        /// </summary>\n        public ICollection Keys\n        {\n            get\n            {\n                return _wrappedDictionary.Keys;\n            }\n        }","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMap.cs#L68-L104","documentation":"PropertyMap's translator setter validates the value: if translator is null it throws ArgumentNullException with SR.WFI_NullArgument ('The translator argument cannot be null.'). To remove a mapping use Remove or set via the underlying dictionary API semantics, not a null delegate — the setter only accepts a valid PropertyTranslator.","triggerScenarios":"Assigning elementHost.PropertyMap[\"Background\"] = null intending to 'clear' a translation; a delegate variable that failed to initialize; a factory method returning null that the caller assigns blindly.","commonSituations":"Developers assuming indexer assignment with null removes the mapping (it throws instead); conditional delegate creation where all branches returned null; deserialized translator delegates that were null.","solutions":["Call PropertyMap.Remove(propertyName) (or Reset) to clear a mapping instead of assigning null.","Assign a no-op translator: (control, value) => { } if you need a mapping present but inert.","Guard the assignment: if (translator != null) map[name] = translator;","Check why the delegate is null — verify factory/initialization code paths return a real PropertyTranslator."],"exampleFix":"// before\nhost.PropertyMap[\"Background\"] = null; // throws\n// after\nhost.PropertyMap.Remove(\"Background\");","handlingStrategy":"type-guard","validationCode":"if (translator != null)\n    host.PropertyMap[propertyName] = translator;\nelse\n    host.PropertyMap.Remove(propertyName); // null means 'remove', not 'assign null'","typeGuard":"static bool CanAssignTranslator(PropertyTranslator translator) => translator is not null;","tryCatchPattern":"try\n{\n    host.PropertyMap[propertyName] = translator;\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"translator\")\n{\n    logger.LogError(ex, \"Translator for '{Property}' was null; use Remove to clear\", propertyName);\n}","preventionTips":["To clear a mapping call PropertyMap.Remove(name), never assign null.","Use a no-op delegate when a mapping must exist but do nothing: (c, v) => { }.","Check delegate-producing factories for null-returning paths."],"tags":["wpf","winforms-integration","propertymap","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"}