{"record":{"id":"0e9cc4517df98bbf","repo":"dotnet/wpf","slug":"sr-format-sr-invalidattributevalue-annotationxmlconstants","errorCode":null,"errorMessage":"SR.Format(SR.InvalidAttributeValue, AnnotationXmlConstants.Attributes.TypeName)","messagePattern":"SR\\.Format\\(SR\\.InvalidAttributeValue, AnnotationXmlConstants\\.Attributes\\.TypeName\\)","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs","lineNumber":640,"sourceCode":"                        break;\n\n                    case AnnotationXmlConstants.Attributes.LastModificationTime:\n                        _modified = XmlConvert.ToDateTime(value);\n                        break;\n\n                    #pragma warning restore 0618\n\n                    case AnnotationXmlConstants.Attributes.TypeName:\n                        ReadOnlySpan<char> typeName = value.AsSpan();\n                        int segmentsLength = typeName.Split(segments, Colon, StringSplitOptions.TrimEntries);\n\n                        if (segmentsLength == 1) // Contains only name\n                        {\n                            ReadOnlySpan<char> name = typeName[segments[0]];\n                            if (name.IsEmpty)\n                            {\n                                // Just a string of whitespace (empty string doesn't get processed)\n                                throw new FormatException(SR.Format(SR.InvalidAttributeValue, AnnotationXmlConstants.Attributes.TypeName));\n                            }\n                            _typeName = new XmlQualifiedName(name.ToString());\n                        }\n                        else if (segmentsLength == 2) //Contains both namespace:name\n                        {\n                            ReadOnlySpan<char> @namespace = typeName[segments[0]];\n                            ReadOnlySpan<char> name = typeName[segments[1]];\n                            if (@namespace.IsEmpty || name.IsEmpty)\n                            {\n                                // One colon, prefix or suffix is empty string or whitespace\n                                throw new FormatException(SR.Format(SR.InvalidAttributeValue, AnnotationXmlConstants.Attributes.TypeName));\n                            }\n                            _typeName = new XmlQualifiedName(name.ToString(), reader.LookupNamespace(@namespace.ToString()));\n                        }\n                        else\n                        {\n                            // More than one colon\n                            throw new FormatException(SR.Format(SR.InvalidAttributeValue, AnnotationXmlConstants.Attributes.TypeName));","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs#L622-L658","documentation":"ReadAttributes throws FormatException with SR.Format(SR.InvalidAttributeValue, TypeName) when the value of the Id or TypeName attribute is just a string of whitespace (empty after splitting on ':'). The TypeName attribute must contain a non-empty name, optionally qualified by a namespace prefix.","triggerScenarios":"Loading annotation XML where the Type attribute is whitespace only (e.g. Type=\" \"), producing a single segment whose name span is empty after trim.","commonSituations":"XML templating that leaves an empty attribute placeholder; XSLT transforms emitting Type=\" \"; hand-edited annotation stores.","solutions":["Ensure the Type attribute contains a valid, non-empty type name before loading","Trim and validate attribute values in the XML-generation pipeline","Catch FormatException in the load path and report which attribute was invalid"],"exampleFix":"// before\n<Annotation Id=\"...\" Type=\" \">\n// after\n<Annotation Id=\"...\" Type=\"Note\">","handlingStrategy":"validation","validationCode":"string typeName = (string)(XDocument.Load(stream).Root?.Attribute(\"Type\")) ?? \"\";\nif (string.IsNullOrWhiteSpace(typeName))\n    throw new InvalidDataException(\"Type attribute is missing or whitespace\");","typeGuard":"bool IsValidTypeNameAttribute(string value) => !string.IsNullOrWhiteSpace(value) && !value.StartsWith(\":\") && !value.EndsWith(\":\") && value.Count(c => c == ':') <= 1;","tryCatchPattern":"try\n{\n    annotation.ReadXml(reader);\n}\ncatch (FormatException ex)\n{\n    logger.LogError(ex, \"Annotation Type attribute value is invalid\");\n    throw new InvalidDataException(\"Invalid Type attribute in annotation XML\", ex);\n}","preventionTips":["Emit Type attributes from validated XmlQualifiedName values, never raw strings","Trim attribute values when generating XML","Add a schema check that Type is present and non-empty before loading"],"tags":["wpf","annotations","xml","format"],"backgroundTag":"invalid-argument-format","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"}