{"record":{"id":"39a0a4a06886d16a","repo":"dotnet/wpf","slug":"sr-stringempty-parameter-name-name","errorCode":null,"errorMessage":"SR.StringEmpty (parameter name: name)","messagePattern":"SR\\.StringEmpty \\(parameter name: name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/RoutedCommand.cs","lineNumber":50,"sourceCode":"        /// <param name=\"name\">Declared Name of the RoutedCommand for Serialization</param>\n        /// <param name=\"ownerType\">Type that is registering the property</param>\n        public RoutedCommand(string name, Type ownerType) : this(name, ownerType, null)\n        {\n        }\n\n        /// <summary>\n        /// RoutedCommand Constructor with Name and OwnerType\n        /// </summary>\n        /// <param name=\"name\">Declared Name of the RoutedCommand for Serialization</param>\n        /// <param name=\"ownerType\">Type that is registering the property</param>\n        /// <param name=\"inputGestures\">Default Input Gestures associated</param>\n        public RoutedCommand(string name, Type ownerType, InputGestureCollection inputGestures)\n        {\n            ArgumentNullException.ThrowIfNull(name);\n\n            if (name.Length == 0)\n            {\n                throw new ArgumentException(SR.StringEmpty, nameof(name));\n            }\n\n            ArgumentNullException.ThrowIfNull(ownerType);\n\n            _name = name;\n            _ownerType = ownerType;\n            _inputGestureCollection = inputGestures;\n        }\n\n        /// <summary>\n        /// RoutedCommand Constructor with Name and OwnerType and command identifier.\n        /// </summary>\n        /// <param name=\"name\">Declared Name of the RoutedCommand for Serialization</param>\n        /// <param name=\"ownerType\">Type that is registering the property</param>\n        /// <param name=\"commandId\">Byte identifier for the command assigned by the owning type</param>\n        internal RoutedCommand(string name, Type ownerType, byte commandId) : this(name, ownerType, null)\n        {\n            _commandId = commandId;","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/RoutedCommand.cs#L32-L68","documentation":"RoutedCommand's constructor requires a non-null, non-empty name string; an empty string throws ArgumentException with SR.StringEmpty. The name is part of the command's identity and is used for display and registration.","triggerScenarios":"new RoutedCommand(\"\", ownerType) or new RoutedCommand(string.Empty, typeof(Window), gestures).","commonSituations":"Command names generated dynamically (e.g. from metadata or resource lookups) that resolve to empty strings when a resource key is missing.","solutions":["Pass a meaningful non-empty name, e.g. new RoutedCommand(\"Save\", typeof(Window)).","Validate the name source before constructing; fall back to a default name if the lookup returns empty.","If the name is unknown, use the parameterless RoutedCommand() constructor which generates one."],"exampleFix":"// before\nvar cmd = new RoutedCommand(resourceKey, typeof(MainWindow)); // resourceKey == \"\"\n// after\nvar name = string.IsNullOrEmpty(resourceKey) ? \"DefaultCommand\" : resourceKey;\nvar cmd = new RoutedCommand(name, typeof(MainWindow));","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name)) throw new ArgumentException(\"Command name must be non-empty\", nameof(name));\nvar cmd = new RoutedCommand(name, ownerType);","typeGuard":null,"tryCatchPattern":"try { var cmd = new RoutedCommand(name, typeof(Window)); } catch (ArgumentException ex) { /* use parameterless RoutedCommand() */ }","preventionTips":["Check name non-empty whenever it comes from resources/config","Prefer the parameterless RoutedCommand() when no name is meaningful","Fail fast on empty resource lookups instead of passing them through"],"tags":["wpf","routed-command","empty-string"],"backgroundTag":"empty-required-field","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"}