diff --git a/src/Controls/samples/Controls.Sample.UITests/Controls.Sample.UITests.csproj b/src/Controls/samples/Controls.Sample.UITests/Controls.Sample.UITests.csproj
index b57f275204e7..0854fd5784ab 100644
--- a/src/Controls/samples/Controls.Sample.UITests/Controls.Sample.UITests.csproj
+++ b/src/Controls/samples/Controls.Sample.UITests/Controls.Sample.UITests.csproj
@@ -23,6 +23,7 @@
true
<_IsPublishing>true
false
+ IL3050;XC0022
$(DefineConstants);NATIVE_AOT
diff --git a/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs b/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs
index d041d10f0307..76d099ab1f74 100644
--- a/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs
+++ b/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs
@@ -517,7 +517,7 @@ static bool IsBindingContextBinding(ElementNode node)
{
// looking for BindingContext="{Binding ...}"
return GetParent(node) is IElementNode parentNode
- && ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out var propertyName)
+ && node.TryGetPropertyName(parentNode, out var propertyName)
&& propertyName.NamespaceURI == ""
&& propertyName.LocalName == nameof(BindableObject.BindingContext);
}
diff --git a/src/Controls/src/SourceGen/CodeBehindGenerator.cs b/src/Controls/src/SourceGen/CodeBehindGenerator.cs
index 844d80fd900f..d511dc445147 100644
--- a/src/Controls/src/SourceGen/CodeBehindGenerator.cs
+++ b/src/Controls/src/SourceGen/CodeBehindGenerator.cs
@@ -358,9 +358,9 @@ static void GenerateXamlCodeBehind(XamlProjectItem? xamlItem, Compilation compil
sb.AppendLine("\t\tprivate void InitializeComponent()");
sb.AppendLine("\t\t{");
- sb.AppendLine("#pragma warning disable IL2026 // The body of InitializeComponent will be replaced by XamlC so LoadFromXaml will never be called in production builds");
+ sb.AppendLine("#pragma warning disable IL2026, IL3050 // The body of InitializeComponent will be replaced by XamlC so LoadFromXaml will never be called in production builds");
sb.AppendLine($"\t\t\tglobal::Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml(this, typeof({rootType}));");
- sb.AppendLine("#pragma warning restore IL2026");
+ sb.AppendLine("#pragma warning restore IL2026, IL3050");
if (namedFields != null)
{
diff --git a/src/Controls/src/Xaml/ApplyPropertiesVisitor.cs b/src/Controls/src/Xaml/ApplyPropertiesVisitor.cs
index 949df4596f62..7243af5f05b6 100644
--- a/src/Controls/src/Xaml/ApplyPropertiesVisitor.cs
+++ b/src/Controls/src/Xaml/ApplyPropertiesVisitor.cs
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Xml;
@@ -14,6 +15,10 @@
namespace Microsoft.Maui.Controls.Xaml
{
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#if !NETSTANDARD
+ [RequiresDynamicCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#endif
class ApplyPropertiesVisitor : IXamlNodeVisitor
{
public static readonly IList Skips = new List {
@@ -49,7 +54,7 @@ public void Visit(ValueNode node, INode parentNode)
return;
- if (TryGetPropertyName(node, parentNode, out XmlName propertyName))
+ if (node.TryGetPropertyName(parentNode, out XmlName propertyName))
{
if (TrySetRuntimeName(propertyName, source, value, node))
return;
@@ -83,7 +88,7 @@ public void Visit(MarkupNode node, INode parentNode)
public void Visit(ElementNode node, INode parentNode)
{
- if (TryGetPropertyName(node, parentNode, out XmlName propertyName) && propertyName == XmlName._CreateContent)
+ if (node.TryGetPropertyName(parentNode, out XmlName propertyName) && propertyName == XmlName._CreateContent)
{
var s0 = Values[parentNode];
if (s0 is ElementTemplate)
@@ -107,7 +112,7 @@ public void Visit(ElementNode node, INode parentNode)
if (!Values.TryGetValue(node, out var value) && Context.ExceptionHandler != null)
return;
- if (propertyName != XmlName.Empty || TryGetPropertyName(node, parentNode, out propertyName))
+ if (propertyName != XmlName.Empty || node.TryGetPropertyName(parentNode, out propertyName))
{
if (Skips.Contains(propertyName))
return;
@@ -229,22 +234,6 @@ public void Visit(ListNode node, INode parentNode)
{
}
- public static bool TryGetPropertyName(INode node, INode parentNode, out XmlName name)
- {
- name = default(XmlName);
- var parentElement = parentNode as IElementNode;
- if (parentElement == null)
- return false;
- foreach (var kvp in parentElement.Properties)
- {
- if (kvp.Value != node)
- continue;
- name = kvp.Key;
- return true;
- }
- return false;
- }
-
internal static bool IsCollectionItem(INode node, INode parentNode)
{
var parentList = parentNode as IListNode;
diff --git a/src/Controls/src/Xaml/Controls.Xaml.csproj b/src/Controls/src/Xaml/Controls.Xaml.csproj
index 58f68a6fb626..e0d0a5df2288 100644
--- a/src/Controls/src/Xaml/Controls.Xaml.csproj
+++ b/src/Controls/src/Xaml/Controls.Xaml.csproj
@@ -22,6 +22,12 @@
.NET Multi-platform App UI (.NET MAUI) is a cross-platform framework for creating native mobile and desktop apps with C# and XAML. This package only contains the XAML tooling. Please install the Microsoft.Maui.Controls package to start using .NET MAUI.
+
+ true
+ true
+ true
+
+
diff --git a/src/Controls/src/Xaml/CreateValuesVisitor.cs b/src/Controls/src/Xaml/CreateValuesVisitor.cs
index ad97b796a311..a7460a9fc0bb 100644
--- a/src/Controls/src/Xaml/CreateValuesVisitor.cs
+++ b/src/Controls/src/Xaml/CreateValuesVisitor.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
@@ -9,6 +10,10 @@
namespace Microsoft.Maui.Controls.Xaml
{
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#if !NETSTANDARD
+ [RequiresDynamicCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#endif
class CreateValuesVisitor : IXamlNodeVisitor
{
public CreateValuesVisitor(HydrationContext context)
@@ -185,7 +190,7 @@ public void Visit(RootNode node, INode parentNode)
public void Visit(ListNode node, INode parentNode)
{
//this is a gross hack to keep ListNode alive. ListNode must go in favor of Properties
- if (ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out XmlName name))
+ if (node.TryGetPropertyName(parentNode, out XmlName name))
node.XmlName = name;
}
diff --git a/src/Controls/src/Xaml/ExpandMarkupsVisitor.cs b/src/Controls/src/Xaml/ExpandMarkupsVisitor.cs
index 6e462f088891..b94858d40e96 100644
--- a/src/Controls/src/Xaml/ExpandMarkupsVisitor.cs
+++ b/src/Controls/src/Xaml/ExpandMarkupsVisitor.cs
@@ -1,10 +1,15 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Xml;
using Microsoft.Maui.Controls.Xaml.Internals;
namespace Microsoft.Maui.Controls.Xaml
{
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#if !NETSTANDARD
+ [RequiresDynamicCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#endif
class ExpandMarkupsVisitor : IXamlNodeVisitor
{
public ExpandMarkupsVisitor(HydrationContext context) => Context = context;
@@ -40,7 +45,7 @@ public void Visit(MarkupNode markupnode, INode parentNode)
{
var parentElement = parentNode as IElementNode;
XmlName propertyName;
- if (!ApplyPropertiesVisitor.TryGetPropertyName(markupnode, parentNode, out propertyName))
+ if (!markupnode.TryGetPropertyName(parentNode, out propertyName))
return;
if (Skips.Contains(propertyName))
return;
@@ -106,6 +111,7 @@ INode ParseExpression(ref string expression, IXmlNamespaceResolver nsResolver, I
return new MarkupExpansionParser { ExceptionHandler = Context.ExceptionHandler }.Parse(match, ref expression, serviceProvider);
}
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
public class MarkupExpansionParser : MarkupExpressionParser, IExpressionParser
{
IElementNode _node;
diff --git a/src/Controls/src/Xaml/FillResourceDictionariesVisitor.cs b/src/Controls/src/Xaml/FillResourceDictionariesVisitor.cs
index ff2bf36d305c..68229b2cb48c 100644
--- a/src/Controls/src/Xaml/FillResourceDictionariesVisitor.cs
+++ b/src/Controls/src/Xaml/FillResourceDictionariesVisitor.cs
@@ -1,11 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Xaml.Internals;
namespace Microsoft.Maui.Controls.Xaml
{
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#if !NETSTANDARD
+ [RequiresDynamicCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#endif
class FillResourceDictionariesVisitor : IXamlNodeVisitor
{
public FillResourceDictionariesVisitor(HydrationContext context) => Context = context;
@@ -38,7 +43,7 @@ public void Visit(ElementNode node, INode parentNode)
return;
//Set RD to VE
- if (typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]) && ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out XmlName propertyName))
+ if (typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]) && node.TryGetPropertyName(parentNode, out XmlName propertyName))
{
if ((propertyName.LocalName == "Resources" ||
propertyName.LocalName.EndsWith(".Resources", StringComparison.Ordinal)) && value is ResourceDictionary)
diff --git a/src/Controls/src/Xaml/MarkupExpressionParser.cs b/src/Controls/src/Xaml/MarkupExpressionParser.cs
index cc5100f42146..6042dea75697 100644
--- a/src/Controls/src/Xaml/MarkupExpressionParser.cs
+++ b/src/Controls/src/Xaml/MarkupExpressionParser.cs
@@ -32,6 +32,7 @@
//
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Microsoft.Maui.Controls.Xaml
@@ -46,6 +47,7 @@ protected struct Property
public object value;
}
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
public object ParseExpression(ref string expression, IServiceProvider serviceProvider)
{
if (serviceProvider == null)
@@ -120,6 +122,7 @@ internal static bool MatchMarkup(out string match, string expression, out int en
return true;
}
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
protected Property ParseProperty(IServiceProvider serviceProvider, ref string remaining)
{
object value = null;
@@ -148,6 +151,7 @@ protected Property ParseProperty(IServiceProvider serviceProvider, ref string re
return new Property { last = next == '}', name = name, strValue = str_value, value = value };
}
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
Property ParsePropertyExpression(string prop, IServiceProvider serviceProvider, ref string remaining)
{
bool last;
diff --git a/src/Controls/src/Xaml/MarkupExtensionParser.cs b/src/Controls/src/Xaml/MarkupExtensionParser.cs
index 3d51baf75c63..e3b53e4f2e24 100644
--- a/src/Controls/src/Xaml/MarkupExtensionParser.cs
+++ b/src/Controls/src/Xaml/MarkupExtensionParser.cs
@@ -1,9 +1,14 @@
using System;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
namespace Microsoft.Maui.Controls.Xaml
{
+ [RequiresUnreferencedCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#if !NETSTANDARD
+ [RequiresDynamicCode(TrimmerConstants.XamlRuntimeParsingNotSupportedWarning)]
+#endif
internal sealed class MarkupExtensionParser : MarkupExpressionParser, IExpressionParser