{"record":{"id":"649b0f126d7d2f9a","repo":"dotnet/wpf","slug":"sr-typenamemustbespecified","errorCode":null,"errorMessage":"SR.TypeNameMustBeSpecified","messagePattern":"SR\\.TypeNameMustBeSpecified","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs","lineNumber":91,"sourceCode":"            _id = Guid.Empty;\n            _created = DateTime.MinValue;\n            _modified = DateTime.MinValue;\n\n            Init();\n        }\n\n        /// <summary>\n        ///     Creates an instance of Annotation with the specified type name.\n        /// </summary>\n        /// <param name=\"annotationType\">fully qualified type name of the new Annotation</param>\n        /// <exception cref=\"ArgumentNullException\">annotationType is null</exception>\n        /// <exception cref=\"ArgumentException\">annotationType's Name or Namespace is null or empty string</exception>\n        public Annotation(XmlQualifiedName annotationType)\n        {\n            ArgumentNullException.ThrowIfNull(annotationType);\n            if (String.IsNullOrEmpty(annotationType.Name))\n            {\n                throw new ArgumentException(SR.TypeNameMustBeSpecified, \"annotationType.Name\");// needs better message\n            }\n            if (String.IsNullOrEmpty(annotationType.Namespace))\n            {\n                throw new ArgumentException(SR.TypeNameMustBeSpecified, \"annotationType.Namespace\");//needs better message\n            }\n\n            _id = Guid.NewGuid();\n            _typeName = annotationType;\n\n            // For an new instance of Annotation, _created should be == with _modified\n            _created = DateTime.Now;\n            _modified = _created;\n\n            Init();\n        }\n\n        /// <summary>\n        ///     Creates an instance of Annotation with the values provided.  This","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Annotation.cs#L73-L109","documentation":"The Annotation(XmlQualifiedName) constructor requires a fully qualified annotation type: ArgumentNullException for a null type, and ArgumentException(SR.TypeNameMustBeSpecified) when the XmlQualifiedName's Name is null or empty. Annotations must identify their type to be persisted and resolved.","triggerScenarios":"new Annotation(new XmlQualifiedName()) or new Annotation(new XmlQualifiedName(\"\")) — an XmlQualifiedName with an empty Name; passing a default-constructed XmlQualifiedName.","commonSituations":"Building the annotation type dynamically and forgetting to set the Name; deserializing configuration where the type name field was blank; passing XmlQualifiedName.Empty (which has an empty Name).","solutions":["Pass an XmlQualifiedName with a non-empty Name, e.g. new XmlQualifiedName(\"note\", \"http://schemas.example.com/annotations\")","Validate annotationType.Name before constructing the Annotation","Supply both Name and Namespace (Namespace is checked next at the same call site)","Fix the source of the blank name — e.g. a config or XML element missing the required attribute"],"exampleFix":"// before\nvar ann = new Annotation(new XmlQualifiedName());\n// after\nvar ann = new Annotation(new XmlQualifiedName(\"note\", \"http://schemas.example.com/annotations\"));","handlingStrategy":"validation","validationCode":"if (annotationType is null || string.IsNullOrEmpty(annotationType.Name) || string.IsNullOrEmpty(annotationType.Namespace))\n    throw new ArgumentException(\"Annotation type requires Name and Namespace.\");\nvar ann = new Annotation(annotationType);","typeGuard":"bool IsValidAnnotationType(XmlQualifiedName t) =>\n    t is { Name: { Length: > 0 }, Namespace: { Length: > 0 } };","tryCatchPattern":"try { var ann = new Annotation(annotationType); }\ncatch (ArgumentException ex) when (ex.ParamName?.StartsWith(\"annotationType\") == true)\n{\n    // log/repair the annotation type before retrying\n}","preventionTips":["Always use the two-argument XmlQualifiedName ctor with an explicit namespace","Validate qualified names read from config/XML before constructing annotations","Define annotation type names/namespaces as shared constants"],"tags":["wpf","annotations","argument","xmlqualifiedname"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}