{"record":{"id":"7964f5a0795985a1","repo":"dotnet/wpf","slug":"sr-format-sr-directivenotfound-name-this-targetnamespace","errorCode":null,"errorMessage":"SR.Format(SR.DirectiveNotFound, name, this.TargetNamespace)","messagePattern":"SR\\.Format\\(SR\\.DirectiveNotFound, name, this\\.TargetNamespace\\)","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XaslNamespace.cs","lineNumber":114,"sourceCode":"                {\n                    return null;\n                }\n            }\n            return xaslType;\n        }\n\n        public override IEnumerable<XamlType> GetAllXamlTypes()\n        {\n            return this.Types as IEnumerable<XamlType>;\n        }\n\n        public override XamlType GetDirectiveType(string name)\n        {\n            XaslType dirType = null;\n            if (!DirectiveTypes.TryGetValue(name, out dirType))\n            {\n                // throw in the early versions, do something better for error path.\n                throw new KeyNotFoundException(SR.Format(SR.DirectiveNotFound, name, this.TargetNamespace));\n            }\n            return dirType;\n        }\n\n        public override IEnumerable<XamlType> GetAllDirectiveTypes()\n        {\n            return DirectiveTypes as IEnumerable<XamlType>;\n        }\n\n        public override XamlProperty GetDirectiveProperty(string name)\n        {\n            XaslMember dirProperty = null;\n            if (!DirectiveProperties.TryGetValue(name, out dirProperty))\n            {\n                // throw in the early versions, do something better for error path.\n                throw new KeyNotFoundException(SR.Format(SR.DirectiveNotFound, name, this.TargetNamespace));\n            }\n            return dirProperty;","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XaslNamespace.cs#L96-L132","documentation":"XaslNamespace.GetDirectiveType looks up a directive name in its DirectiveTypes dictionary and throws KeyNotFoundException(SR.Format(SR.DirectiveNotFound, name, TargetNamespace)) when the directive is not registered. The code comment notes this is an early-version behavior and the error path is expected to improve.","triggerScenarios":"Requesting a directive XamlType via GetDirectiveType(name) where name is not present in the namespace's DirectiveTypes, e.g. a typo'd directive like 'x:Ky' or a directive from a different xaml namespace.","commonSituations":"Hand-written XAML with misspelled x: directives; parsing documents referencing directives from a namespace whose XaslNamespace was built without that directive registered; version drift where a directive was added in a newer schema.","solutions":["Fix the directive name in the XAML or call site to match a registered directive for this TargetNamespace.","Verify the XaslNamespace instance you are querying actually owns the directive (check TargetNamespace in the message).","Use GetAllDirectiveTypes() first to enumerate valid names before lookup.","Wrap the lookup in try/catch for KeyNotFoundException if unknown directives are expected."],"exampleFix":"// before\nvar t = xamlNamespace.GetDirectiveType(\"x:Shareable\");\n// after\nvar t = xamlNamespace.GetAllDirectiveTypes().Any(d => /* name matches */)\n    ? xamlNamespace.GetDirectiveType(\"x:Shared\")\n    : null;","handlingStrategy":"validation","validationCode":"bool exists = xamlNamespace.GetAllDirectiveTypes()\n    .Any(d => /* d matches requested name */);\nif (!exists) throw new ArgumentException($\"Unknown directive '{name}' in {xamlNamespace.TargetNamespace}\");","typeGuard":null,"tryCatchPattern":"try { var t = ns.GetDirectiveType(name); } catch (KeyNotFoundException ex) { /* handle unknown directive for ns.TargetNamespace */ }","preventionTips":["Validate directive names against GetAllDirectiveTypes() first","Confirm the TargetNamespace owns the directive","Fix XAML spelling of x: directives"],"tags":["xaml","directive","lookup-failed"],"backgroundTag":"resource-not-found","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"}