1+ using System ;
12using System . Collections . Generic ;
23using System . Linq ;
34using System . Xml ;
@@ -30,7 +31,7 @@ static IList<XmlnsDefinitionAttribute> GatherXmlnsDefinitionAttributes(ModuleDef
3031 }
3132 else
3233 {
33- // Use standard XF assemblies
34+ // Use standard MAUI assemblies
3435 // (Should only happen in unit tests)
3536 var requiredAssemblies = new [ ] {
3637 typeof ( XamlLoader ) . Assembly ,
@@ -39,7 +40,18 @@ static IList<XmlnsDefinitionAttribute> GatherXmlnsDefinitionAttributes(ModuleDef
3940 foreach ( var assembly in requiredAssemblies )
4041 foreach ( XmlnsDefinitionAttribute attribute in assembly . GetCustomAttributes ( typeof ( XmlnsDefinitionAttribute ) , false ) )
4142 {
42- attribute . AssemblyName = attribute . AssemblyName ?? assembly . FullName ;
43+ attribute . AssemblyName ??= assembly . FullName ;
44+ //maui, and x: xmlns are protected
45+ if ( attribute . XmlNamespace != XamlParser . MauiGlobal
46+ && attribute . XmlNamespace . StartsWith ( "http://schemas.microsoft.com/" , StringComparison . OrdinalIgnoreCase )
47+ && ! attribute . AssemblyName . StartsWith ( "Microsoft" , StringComparison . OrdinalIgnoreCase )
48+ && ! attribute . AssemblyName . StartsWith ( "System" , StringComparison . OrdinalIgnoreCase )
49+ && ! attribute . AssemblyName . StartsWith ( "mscorlib" , StringComparison . OrdinalIgnoreCase ) )
50+ {
51+ throw new BuildException ( BuildExceptionCode . InvalidXaml , null , null ,
52+ $ "Protected Xmlns { attribute . XmlNamespace } . Can't add assembly { attribute . AssemblyName } .") ;
53+ }
54+
4355 xmlnsDefinitions . Add ( attribute ) ;
4456 }
4557 }
@@ -55,9 +67,18 @@ static void GatherXmlnsDefinitionAttributes(List<XmlnsDefinitionAttribute> xmlns
5567 {
5668 var attr = GetXmlnsDefinition ( ca , asmDef ) ;
5769 //only add globalxmlns definition from the current assembly
58- if ( attr . XmlNamespace == XamlParser . MauiGlobal
70+ if ( attr . XmlNamespace == XamlParser . MauiGlobal
5971 && asmDef != currentAssembly )
6072 continue ;
73+ if ( attr . XmlNamespace != XamlParser . MauiGlobal
74+ && attr . XmlNamespace . StartsWith ( "http://schemas.microsoft.com/" , StringComparison . OrdinalIgnoreCase )
75+ && ! attr . AssemblyName . StartsWith ( "Microsoft" , StringComparison . OrdinalIgnoreCase )
76+ && ! attr . AssemblyName . StartsWith ( "System" , StringComparison . OrdinalIgnoreCase )
77+ && ! attr . AssemblyName . StartsWith ( "mscorlib" , StringComparison . OrdinalIgnoreCase ) )
78+ {
79+ throw new BuildException ( BuildExceptionCode . InvalidXaml , null , null ,
80+ $ "Protected Xmlns { attr . XmlNamespace } . Can't add assembly { attr . AssemblyName } .") ;
81+ }
6182 xmlnsDefinitions . Add ( attr ) ;
6283 }
6384 }
0 commit comments