{"record":{"id":"090e5a3b5c6a5804","repo":"dotnet/wpf","slug":"sr-invalidpropertyvalue-formatted-with-value-name-invalid","errorCode":null,"errorMessage":"SR.InvalidPropertyValue formatted with (value, \"Name\") - invalid Storyboard.Name value","messagePattern":"SR\\.InvalidPropertyValue formatted with \\(value, \"Name\"\\) - invalid Storyboard\\.Name value","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/BeginStoryboard.cs","lineNumber":105,"sourceCode":"    /// by a control action such as pause and resume.  Defaults to null, which\n    /// means this storyboard is not going to be interactively controlled.\n    /// </summary>\n    // Null == no interactive control == \"Fire and Forget\"\n    [DefaultValue(null)]\n    public string Name\n    {\n        get\n        {\n            return _name;\n        }\n        set\n        {\n            ThrowIfSealed();\n\n            if(value != null && !System.Windows.Markup.NameValidationHelper.IsValidIdentifierName(value))\n            {\n                // Duplicate the error string thrown from DependencyObject.SetValueValidateParams\n                throw new ArgumentException(SR.Format(SR.InvalidPropertyValue, value, \"Name\"));\n            }\n            \n            // Null is OK - it's to remove whatever name was previously set.\n            _name = value;\n        }\n    }\n\n    private void ThrowIfSealed()\n    {\n        if (IsSealed)\n        {\n            throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"BeginStoryboard\"));\n        }\n    }\n    \n    // Bug #1329664 workaround to make beta 2\n    // Remove thread affinity when sealed, but before doing that, snapshot the\n    //  current Storyboard value and remove *its* thread affinity too.","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/BeginStoryboard.cs#L87-L123","documentation":"BeginStoryboard.Name throws ArgumentException (SR.InvalidPropertyValue formatted with the bad value and \"Name\") when assigned a string that is not a valid XAML identifier name. This mirrors the validation DependencyObject.SetValueValidateParams performs; the name is used to register the storyboard for interactive control.","triggerScenarios":"Setting BeginStoryboard.Name to a string containing invalid identifier characters (spaces, leading digits, punctuation, non-identifier symbols) as checked by NameValidationHelper.IsValidIdentifierName.","commonSituations":"XAML with a BeginStoryboard Name containing spaces or starting with a digit, or programmatically generating names from user input without sanitization.","solutions":["Use a valid XAML name: start with a letter or underscore, contain only letters, digits, underscores.","Sanitize generated names (replace invalid characters, prefix with a letter) before assigning.","Validate with System.Windows.Markup.NameValidationHelper before setting."],"exampleFix":"// before\nbeginStoryboard.Name = \"my storyboard 1\";\n// after\nbeginStoryboard.Name = \"MyStoryboard1\";","handlingStrategy":"validation","validationCode":"bool IsValidXamlName(string name) =>\n    name != null && System.Text.RegularExpressions.Regex.IsMatch(name, \"^[A-Za-z_][A-Za-z0-9_.]*$\");\nif (IsValidXamlName(candidateName)) beginStoryboard.Name = candidateName;","typeGuard":null,"tryCatchPattern":"try { beginStoryboard.Name = name; }\ncatch (ArgumentException ex) { beginStoryboard.Name = SanitizeName(name); }","preventionTips":["Generate names that start with a letter or underscore and use only letters/digits/underscores","Sanitize user- or config-derived names before assigning to Name","Test XAML with names containing spaces or digits early"],"tags":["wpf","animation","naming","validation","csharp"],"backgroundTag":"invalid-identifier","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"}