{"record":{"id":"e43413c8854166b1","repo":"PrismLibrary/Prism","slug":"resources-stringcannotbenullorempty","errorCode":null,"errorMessage":"Resources.StringCannotBeNullOrEmpty","messagePattern":"Resources\\.StringCannotBeNullOrEmpty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs","lineNumber":262,"sourceCode":"            return Add(view, null, false);\n        }\n\n        /// <summary>\n        /// Adds a new view to the region.\n        /// </summary>\n        /// <param name=\"view\">The view to add.</param>\n        /// <param name=\"viewName\">The name of the view. This can be used to retrieve it later by calling <see cref=\"IRegion.GetView\"/>.</param>\n\n#if !AVALONIA\n        /// <returns>The <see cref=\"IRegionManager\"/> that is set on the view if it is a <see cref=\"DependencyObject\"/>. It will be the current region manager when using this overload.</returns>\n#else\n        /// <returns>The <see cref=\"IRegionManager\"/> that is set on the view if it is a <see cref=\"AvaloniaObject\"/>. It will be the current region manager when using this overload.</returns>\n#endif\n        public IRegionManager Add(object view, string viewName)\n        {\n            if (string.IsNullOrEmpty(viewName))\n            {\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, \"viewName\"));\n            }\n\n            return Add(view, viewName, false);\n        }\n\n        /// <summary>\n        /// Adds a new view to the region.\n        /// </summary>\n        /// <param name=\"view\">The view to add.</param>\n        /// <param name=\"viewName\">The name of the view. This can be used to retrieve it later by calling <see cref=\"IRegion.GetView\"/>.</param>\n        /// <param name=\"createRegionManagerScope\">When <see langword=\"true\"/>, the added view will receive a new instance of <see cref=\"IRegionManager\"/>, otherwise it will use the current region manager for this region.</param>\n\n#if !AVALONIA\n        /// <returns>The <see cref=\"IRegionManager\"/> that is set on the view if it is a <see cref=\"DependencyObject\"/>.</returns>\n#else\n        /// <returns>The <see cref=\"IRegionManager\"/> that is set on the view if it is a <see cref=\"AvaloniaObject\"/>.</returns>\n#endif\n        public virtual IRegionManager Add(object view, string viewName, bool createRegionManagerScope)","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs#L244-L280","documentation":"The Region.Add(object view, string viewName) overload requires a non-empty viewName; passing null or empty throws ArgumentException formatted with StringCannotBeNullOrEmpty and parameter name \"viewName\". The name is stored in ItemMetadata as the key for later GetView calls.","triggerScenarios":"Calling region.Add(myView, null) or region.Add(myView, \"\") — e.g. a variable viewName that was never assigned or came from an empty property.","commonSituations":"Programmatic view registration where the view name comes from user input, a config value, or a dictionary lookup that returned null; refactoring that dropped a literal name argument.","solutions":["Provide a valid non-empty viewName when calling Add.","If the view needs no name, use the nameless overload region.Add(view) instead.","Validate the name source (config/binding) before calling Add."],"exampleFix":"// before\nregion.Add(editView, viewName); // viewName may be null\n// after\nif (!string.IsNullOrEmpty(viewName))\n    region.Add(editView, viewName);\nelse\n    region.Add(editView);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(viewName))\n    region.Add(view);\nelse\n    region.Add(view, viewName);","typeGuard":null,"tryCatchPattern":"try\n{\n    region.Add(view, viewName);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogError(ex, \"viewName was null or empty.\");\n}","preventionTips":["Use the nameless Add(view) overload when no name is needed.","Validate name-producing inputs (config, bindings) before Add.","Centralize view registration in a helper that validates names."],"tags":["wpf","prism","region","argument","null"],"backgroundTag":"missing-required-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}