{"record":{"id":"07a9915e1f00e318","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedattribute-reader-localname","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Annotation)","messagePattern":"SR\\.Format\\(SR\\.UnexpectedAttribute, reader\\.LocalName, AnnotationXmlConstants\\.Elements\\.Annotation\\)","errorType":"exception","errorClass":"XmlException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs","lineNumber":664,"sourceCode":"                            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));\n                        }\n                        break;\n\n                    default:\n                        if (!Annotation.IsNamespaceDeclaration(reader))\n                           throw new XmlException(SR.Format(SR.UnexpectedAttribute, reader.LocalName, AnnotationXmlConstants.Elements.Annotation));\n                       break;\n                }\n            }\n\n            // Test to see if any required attribute was missing\n            if (_id.Equals(Guid.Empty))\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.Id, AnnotationXmlConstants.Elements.Annotation));\n            }\n            if (_created.Equals(DateTime.MinValue))\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.CreationTime, AnnotationXmlConstants.Elements.Annotation));\n            }\n            if (_modified.Equals(DateTime.MinValue))\n            {\n                throw new XmlException(SR.Format(SR.RequiredAttributeMissing, AnnotationXmlConstants.Attributes.LastModificationTime, AnnotationXmlConstants.Elements.Annotation));\n            }\n            if (_typeName == null)","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs#L646-L682","documentation":"Annotation.ReadAttributes rejects any attribute on the <Annotation> element that is not a recognized attribute (Id, TypeName, CreationTime, LastModificationTime) and not a namespace declaration. The library throws XmlException to signal that the annotation XML stream is not valid per the annotations schema.","triggerScenarios":"Deserializing an annotation store XML (Annotation.ReadXml / XmlSerializer) that contains an <Annotation> element with an unknown attribute, e.g. a custom attribute or a misspelled attribute name such as 'CreatTime'.","commonSituations":"Hand-edited annotation files, XML produced by a different annotation tool or newer/older WPF version with extra attributes, or XML transformed through schemas that added attributes.","solutions":["Remove or rename the unexpected attribute on the <Annotation> element so it matches the schema (Id, TypeName, CreationTime, LastModificationTime).","Move custom metadata into a namespace-declared attribute or a child element such as <Cargos> instead of a plain attribute.","Regenerate the annotation XML from a trusted source rather than hand-editing.","If the attribute is a legitimate extension, add the xmlns declaration so Annotation.IsNamespaceDeclaration returns true for it."],"exampleFix":"// before\n<Annotation Id=\"...\" Author=\"me\" ...>\n// after\n<Annotation Id=\"...\" xmlns:ex=\"http://example.com/annot\" ex:Author=\"me\" ...>","handlingStrategy":"validation","validationCode":"bool IsValidAnnotationXml(XElement el) => el.Name.LocalName == \"Annotation\" && el.Attributes().All(a => new[]{\"Id\",\"TypeName\",\"CreationTime\",\"LastModificationTime\"}.Contains(a.Name.LocalName) || !string.IsNullOrEmpty(a.Name.NamespaceName));","typeGuard":null,"tryCatchPattern":"try { using var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)); serializer.Deserialize(ms); } catch (XmlException ex) { log.Error(\"Invalid annotation XML attribute: \" + ex.Message); }","preventionTips":["Never hand-edit annotation XML; always round-trip through AnnotationStore.","Validate annotation XML against the annotations schema before loading.","Put custom metadata in namespaced attributes or Cargos, not plain attributes.","Pin the WPF version that produced the files across write/read paths."],"tags":["xml","wpf","deserialization"],"backgroundTag":"schema-validation-failed","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"}