{"record":{"id":"52286cae52c1d115","repo":"PrismLibrary/Prism","slug":"the-provided-string-argument-0-must-not-be-null-or-empty","errorCode":null,"errorMessage":"The provided String argument {0} must not be null or empty.","messagePattern":"The provided String argument (.+?) must not be null or empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Regions/Region.cs","lineNumber":243,"sourceCode":"    /// </summary>\n    /// <param name=\"view\">The view to add.</param>\n    /// <returns>The <see cref=\"IRegionManager\"/> that is set on the view if it is a <see cref=\"VisualElement\"/>. It will be the current region manager when using this overload.</returns>\n    public IRegionManager Add(object view)\n    {\n        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    /// <returns>The <see cref=\"IRegionManager\"/> that is set on the view if it is a <see cref=\"VisualElement\"/>. It will be the current region manager when using this overload.</returns>\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, nameof(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    /// <returns>The <see cref=\"IRegionManager\"/> that is set on the view if it is a <see cref=\"VisualElement\"/>.</returns>\n    public virtual IRegionManager Add(object view, string viewName, bool createRegionManagerScope)\n    {\n        IRegionManager manager = createRegionManagerScope ? RegionManager.CreateRegionManager() : RegionManager;\n        InnerAdd(view, viewName, manager);\n        return manager;\n    }","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Regions/Region.cs#L225-L261","documentation":"The Add(object view, string viewName) overload validates that viewName is non-null and non-empty, formatting Resources.StringCannotBeNullOrEmpty with the parameter name. A view registered by name must have a key that GetView can later look up; an empty key is meaningless. It forwards to Add(view, viewName, false) only after validation.","triggerScenarios":"Calling region.Add(view, \"\") or region.Add(view, null); passing a viewName variable built from missing metadata (e.g. control.Name or a config value that is empty).","commonSituations":"Dynamic view registration where the view name comes from data binding, XAML names, or settings that are not populated; refactors that dropped the hardcoded view name string.","solutions":["Pass a non-empty viewName when adding the view.","If the view does not need a lookup key, use the nameless overload region.Add(view).","Validate/derive the name at the call site before calling Add."],"exampleFix":"// before\nregion.Add(myView, viewName); // viewName may be null/empty\n// after\nif (string.IsNullOrEmpty(viewName))\n    viewName = nameof(MyView);\nregion.Add(myView, viewName);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(viewName))\n    viewName = view.GetType().Name;\nregion.Add(view, viewName);","typeGuard":"bool IsValidViewName(string n) => !string.IsNullOrEmpty(n);","tryCatchPattern":"try\n{\n    region.Add(view, viewName);\n}\ncatch (ArgumentException)\n{\n    // register without a name or with a default name\n}","preventionTips":["Use the nameless Add(view) overload when no lookup key is needed.","Default to view.GetType().Name when a name is unavailable.","Validate names derived from bindings/config before calling Add."],"tags":["invalid-argument","empty-string","view-registration","prism"],"backgroundTag":"empty-required-field","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"}