1+ using System ;
12using System . Collections . Generic ;
23using System . Linq ;
34using System . Xml ;
@@ -26,14 +27,24 @@ static IList<XmlnsDefinitionAttribute> GatherXmlnsDefinitionAttributes(ModuleDef
2627 if ( ca . AttributeType . FullName == typeof ( XmlnsDefinitionAttribute ) . FullName )
2728 {
2829 var attr = GetXmlnsDefinition ( ca , asmDef ) ;
30+ //maui, and x: xmlns are protected
31+ if ( attr . XmlNamespace . StartsWith ( "http://schemas.microsoft.com/" , StringComparison . OrdinalIgnoreCase ) &&
32+ ! attr . AssemblyName . StartsWith ( "Microsoft" , StringComparison . OrdinalIgnoreCase ) &&
33+ ! attr . AssemblyName . StartsWith ( "System" , StringComparison . OrdinalIgnoreCase ) &&
34+ ! attr . AssemblyName . StartsWith ( "mscorlib" , StringComparison . OrdinalIgnoreCase ) )
35+ {
36+ throw new BuildException ( BuildExceptionCode . InvalidXaml , null , null ,
37+ $ "Protected Xmlns { attr . XmlNamespace } . Can't add assembly { attr . AssemblyName } .") ;
38+ }
39+
2940 xmlnsDefinitions . Add ( attr ) ;
3041 }
3142 }
3243 }
3344 }
3445 else
3546 {
36- // Use standard XF assemblies
47+ // Use standard MAUI assemblies
3748 // (Should only happen in unit tests)
3849 var requiredAssemblies = new [ ] {
3950 typeof ( XamlLoader ) . Assembly ,
@@ -42,7 +53,16 @@ static IList<XmlnsDefinitionAttribute> GatherXmlnsDefinitionAttributes(ModuleDef
4253 foreach ( var assembly in requiredAssemblies )
4354 foreach ( XmlnsDefinitionAttribute attribute in assembly . GetCustomAttributes ( typeof ( XmlnsDefinitionAttribute ) , false ) )
4455 {
45- attribute . AssemblyName = attribute . AssemblyName ?? assembly . FullName ;
56+ attribute . AssemblyName ??= assembly . FullName ;
57+ //maui, and x: xmlns are protected
58+ if ( attribute . XmlNamespace . StartsWith ( "http://schemas.microsoft.com/" , StringComparison . OrdinalIgnoreCase ) &&
59+ ! attribute . AssemblyName . StartsWith ( "Microsoft" , StringComparison . OrdinalIgnoreCase ) &&
60+ ! attribute . AssemblyName . StartsWith ( "System" , StringComparison . OrdinalIgnoreCase ) &&
61+ ! attribute . AssemblyName . StartsWith ( "mscorlib" , StringComparison . OrdinalIgnoreCase ) )
62+ {
63+ throw new BuildException ( BuildExceptionCode . InvalidXaml , null , null ,
64+ $ "Protected Xmlns { attribute . XmlNamespace } . Can't add assembly { attribute . AssemblyName } .") ; }
65+
4666 xmlnsDefinitions . Add ( attribute ) ;
4767 }
4868 }
0 commit comments