{"record":{"id":"a9c492e587ae5d2b","repo":"dotnet/maui","slug":"xc0066","errorCode":"XC0066","errorMessage":"Invalid Xaml \"Protected Xmlns {xmlNamespace}. Can't add assembly {assemblyName}.\"","messagePattern":"Invalid Xaml \"Protected Xmlns (.+?)\\. Can't add assembly (.+?)\\.\"","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Build.Tasks/XmlTypeExtensions.cs","lineNumber":62,"sourceCode":"\t\t\t\t\t\txmlnsDefinitions.Add(attribute);\n\t\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn xmlnsDefinitions;\n\t\t}\n\t\tstatic void ValidateProtectedXmlns(string xmlNamespace, string assemblyName)\n\t\t{\n\t\t\t//maui, and x: xmlns are protected\n\t\t\tif (xmlNamespace != XamlParser.MauiUri && xmlNamespace != XamlParser.X2009Uri)\n\t\t\t\treturn;\n\n\t\t\t//we know thos assemblies, they are fine in maui or x xmlns\n\t\t\tif (assemblyName.StartsWith(\"Microsoft\", StringComparison.OrdinalIgnoreCase)\n\t\t\t\t|| assemblyName.StartsWith(\"System\", StringComparison.OrdinalIgnoreCase)\n\t\t\t\t|| assemblyName.StartsWith(\"mscorlib\", StringComparison.OrdinalIgnoreCase))\n\t\t\t\treturn;\n\n\t\t\tthrow new BuildException(BuildExceptionCode.InvalidXaml, null, null,\n\t\t\t\t$\"Protected Xmlns {xmlNamespace}. Can't add assembly {assemblyName}.\");\n\n\t\t}\n\t\tstatic void GatherXmlnsDefinitionAttributes(List<XmlnsDefinitionAttribute> xmlnsDefinitions, AssemblyDefinition asmDef, AssemblyDefinition currentAssembly)\n\t\t{\n\t\t\tforeach (var ca in asmDef.CustomAttributes)\n\t\t\t{\n\t\t\t\tif (ca.AttributeType.FullName == _xmlnsDefinitionName)\n\t\t\t\t{\n\t\t\t\t\tvar attr = GetXmlnsDefinition(ca, asmDef);\n\t\t\t\t\t//only add globalxmlns definition from the current assembly\n\t\t\t\t\tif (attr.XmlNamespace == XamlParser.MauiGlobalUri\n\t\t\t\t\t\t&& asmDef != currentAssembly)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tValidateProtectedXmlns(attr.XmlNamespace, attr.AssemblyName);\n\t\t\t\t\txmlnsDefinitions.Add(attr);\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Build.Tasks/XmlTypeExtensions.cs#L44-L80","documentation":"Raised when an assembly tries to register itself into one of the protected XML namespaces (the MAUI uri or the XAML 2009 uri) via a XmlnsDefinitionAttribute, but its assembly name does not begin with Microsoft/System/mscorlib. Those namespaces are reserved for the framework, so the build task rejects the registration as invalid XAML.","triggerScenarios":"ValidateProtectedXmlns is called with xmlNamespace equal to XamlParser.MauiUri or XamlParser.X2009Uri and an assemblyName that does not StartsWith Microsoft/System/mscorlib (case-insensitive), reaching the final throw.","commonSituations":"A third-party library copies a Maui sample assembly attribute and reuses 'http://schemas.microsoft.com/dotnet/2021/maui' as its XmlnsDefinition; a library targets the XAML 2009 namespace intentionally; a generated assembly accidentally emits the reserved uri.","solutions":["Change the XmlnsDefinition attribute to use your own custom uri, e.g. 'http://mycompany.com/schemas/mylib'.","If you only want a clr-namespace shortcut, register under an unreserved uri and reference the clr-namespace directly in XAML.","Remove the XmlnsDefinition attribute entirely if you do not need a custom xmlns prefix for your controls."],"exampleFix":"// before\n[assembly: XmlnsDefinition(\"http://schemas.microsoft.com/dotnet/2021/maui\", \"MyLib.Controls\")]\n// after\n[assembly: XmlnsDefinition(\"http://mycompany.com/schemas/mylib\", \"MyLib.Controls\")]","handlingStrategy":"validation","validationCode":"// Assembly-level guard: never register a third-party assembly into a reserved xmlns.\nstatic readonly HashSet<string> Reserved = new() { XamlParser.MauiUri, XamlParser.X2009Uri };\nstatic string SafeXmlns(string desired, string assemblyName)\n    => Reserved.Contains(desired) && !assemblyName.StartsWith(\"Microsoft\", StringComparison.OrdinalIgnoreCase)\n        ? $\"http://{assemblyName.ToLowerInvariant()}.local/schemas\"\n        : desired;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use your own company/product uri for XmlnsDefinition, never the MAUI or XAML 2009 uri.","Code-review any new [assembly: XmlnsDefinition(...)] for a reserved namespace.","Document your library's custom xmlns in its README so consumers use the right prefix."],"tags":["xaml","xmlns","build-task","protected-namespace","xc0066"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}