diff --git a/src/SourceGenerators/System.Xaml/Assembly/Class1.cs b/src/SourceGenerators/System.Xaml/Assembly/Class1.cs
new file mode 100644
index 000000000000..1b23b3005f4c
--- /dev/null
+++ b/src/SourceGenerators/System.Xaml/Assembly/Class1.cs
@@ -0,0 +1,85 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace System.Diagnostics.CodeAnalysis
+{
+ ///
+ /// Suppresses reporting of a specific rule violation, allowing multiple suppressions on a
+ /// single code artifact.
+ ///
+ ///
+ /// is different than
+ /// in that it doesn't have a
+ /// . So it is always preserved in the compiled assembly.
+ ///
+ [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
+ internal sealed class UnconditionalSuppressMessageAttribute : Attribute
+ {
+ ///
+ /// Initializes a new instance of the
+ /// class, specifying the category of the tool and the identifier for an analysis rule.
+ ///
+ /// The category for the attribute.
+ /// The identifier of the analysis rule the attribute applies to.
+ public UnconditionalSuppressMessageAttribute(string category, string checkId)
+ {
+ Category = category;
+ CheckId = checkId;
+ }
+
+ ///
+ /// Gets the category identifying the classification of the attribute.
+ ///
+ ///
+ /// The property describes the tool or tool analysis category
+ /// for which a message suppression attribute applies.
+ ///
+ public string Category { get; }
+
+ ///
+ /// Gets the identifier of the analysis tool rule to be suppressed.
+ ///
+ ///
+ /// Concatenated together, the and
+ /// properties form a unique check identifier.
+ ///
+ public string CheckId { get; }
+
+ ///
+ /// Gets or sets the scope of the code that is relevant for the attribute.
+ ///
+ ///
+ /// The Scope property is an optional argument that specifies the metadata scope for which
+ /// the attribute is relevant.
+ ///
+ public string Scope { get; set; }
+
+ ///
+ /// Gets or sets a fully qualified path that represents the target of the attribute.
+ ///
+ ///
+ /// The property is an optional argument identifying the analysis target
+ /// of the attribute. An example value is "System.IO.Stream.ctor():System.Void".
+ /// Because it is fully qualified, it can be long, particularly for targets such as parameters.
+ /// The analysis tool user interface should be capable of automatically formatting the parameter.
+ ///
+ public string Target { get; set; }
+
+ ///
+ /// Gets or sets an optional argument expanding on exclusion criteria.
+ ///
+ ///
+ /// The property is an optional argument that specifies additional
+ /// exclusion where the literal metadata target is not sufficiently precise. For example,
+ /// the cannot be applied within a method,
+ /// and it may be desirable to suppress a violation against a statement in the method that will
+ /// give a rule violation, but not against all statements in the method.
+ ///
+ public string MessageId { get; set; }
+
+ ///
+ /// Gets or sets the justification for suppressing the code analysis message.
+ ///
+ public string Justification { get; set; }
+ }
+}
diff --git a/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs b/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs
index 5945a613bfbc..49b8bf3f1eec 100644
--- a/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs
+++ b/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeName.cs
@@ -22,11 +22,13 @@
//
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
namespace Uno.Xaml.Schema
{
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Types manipulated here have been marked earlier")]
public class XamlTypeName
{
public static XamlTypeName Parse (string typeName, IXamlNamespaceResolver namespaceResolver)
diff --git a/src/SourceGenerators/System.Xaml/System.Xaml/TypeExtensionMethods.cs b/src/SourceGenerators/System.Xaml/System.Xaml/TypeExtensionMethods.cs
index 3ce94720c202..2f93fdc67d6f 100644
--- a/src/SourceGenerators/System.Xaml/System.Xaml/TypeExtensionMethods.cs
+++ b/src/SourceGenerators/System.Xaml/System.Xaml/TypeExtensionMethods.cs
@@ -24,6 +24,7 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
@@ -32,6 +33,7 @@
namespace Uno.Xaml
{
+ [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Types manipulated here have been marked earlier")]
static class TypeExtensionMethods
{
#region inheritance search and custom attribute provision
diff --git a/src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs b/src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs
index 87304504553e..5caeb580b304 100644
--- a/src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs
+++ b/src/SourceGenerators/System.Xaml/System.Xaml/XamlSchemaContext.cs
@@ -29,6 +29,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
@@ -43,6 +44,8 @@ namespace Uno.Xaml
// it registers AssemblyLoaded event on CurrentDomain when it should
// reflect dynamic in-scope asemblies.
// It should be released at finalizer.
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Types manipulated here have been marked earlier")]
+ [UnconditionalSuppressMessage("Trimming", "IL2055", Justification = "Types manipulated here have been marked earlier")]
public class XamlSchemaContext
{
private static readonly char[] _semicolonArray = new char[] { ';' };
diff --git a/src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs b/src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs
index 53ddfb263394..fd13a69c0d74 100644
--- a/src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs
+++ b/src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs
@@ -30,9 +30,11 @@
using Uno.Xaml.Schema;
using System.Xml.Serialization;
using System.Globalization;
+using System.Diagnostics.CodeAnalysis;
namespace Uno.Xaml
{
+ [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Types manipulated here have been marked earlier")]
public class XamlType : IEquatable
{
public XamlType (Type underlyingType, XamlSchemaContext schemaContext)
diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/BindableTypeProviders/BindableTypeProvidersGenerationTask.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/BindableTypeProviders/BindableTypeProvidersGenerationTask.cs
index 1b0cd2a91d77..2adb95aac7a0 100644
--- a/src/SourceGenerators/Uno.UI.SourceGenerators/BindableTypeProviders/BindableTypeProvidersGenerationTask.cs
+++ b/src/SourceGenerators/Uno.UI.SourceGenerators/BindableTypeProviders/BindableTypeProvidersGenerationTask.cs
@@ -292,6 +292,8 @@ where field.IsStatic
writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.SuppressMessage(\"Microsoft.Maintainability\", \"CA1502:AvoidExcessiveComplexity\", Justification=\"Must be ignored even if generated code is checked.\")]");
writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.SuppressMessage(\"Microsoft.Maintainability\", \"CA1506:AvoidExcessiveClassCoupling\", Justification = \"Must be ignored even if generated code is checked.\")]");
writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.SuppressMessage(\"Microsoft.Maintainability\", \"CA1505:AvoidUnmaintainableCode\", Justification = \"Must be ignored even if generated code is checked.\")]");
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2026\")]");
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2111\")]");
using (writer.BlockInvariant("internal static global::Uno.UI.DataBinding.IBindableType Build()"))
{
writer.AppendLineIndented("return Build(null);");
diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs
index 5f23b7778c7a..c1e23e45dce8 100644
--- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs
+++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs
@@ -930,6 +930,8 @@ private void BuildChildSubclasses(IIndentedStringBuilder writer, bool isTopLevel
WriteMetadataNewTypeAttribute(writer);
writer.AppendLineIndented("[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]");
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2026\")]");
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2111\")]");
using (writer.BlockInvariant($"{classAccessibility} class {className} {hrInterfaceImpl}"))
{
BuildBaseUri(writer);
@@ -1317,6 +1319,10 @@ private void BuildTopLevelResourceDictionary(IIndentedStringBuilder writer, Xaml
{
using (writer.BlockInvariant("namespace {0}", _defaultNamespace))
{
+
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2026\")]");
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2111\")]");
+
using (writer.BlockInvariant("public sealed partial class GlobalStaticResources"))
{
BuildBaseUri(writer);
@@ -1595,6 +1601,7 @@ private bool BuildDefaultStylesRegistration(IIndentedStringBuilder writer, XamlM
writer.AppendLine();
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2075\")]");
using (writer.BlockInvariant("public static void RegisterDefaultStyles_{0}()", _fileUniqueId))
{
if (_isHotReloadEnabled)
@@ -1782,6 +1789,8 @@ private void BuildSingleTimeInitializer(IIndentedStringBuilder writer, string in
TryAnnotateWithGeneratorSource(writer);
using (ResourceOwnerScope())
{
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2026\")]");
+ writer.AppendLineIndented("[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2111\")]");
writer.AppendLineIndented($"private object {initializerName}(object {CurrentResourceOwner}) =>");
using (writer.Indent())
{
diff --git a/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObjectMetadataProvider.wasm.cs b/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObjectMetadataProvider.wasm.cs
index 27de49bac4e8..fd765eb19877 100644
--- a/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObjectMetadataProvider.wasm.cs
+++ b/src/Uno.Foundation.Runtime.WebAssembly/Interop/JSObjectMetadataProvider.wasm.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Threading;
@@ -11,9 +12,12 @@ namespace Uno.Foundation.Interop
///
/// Provider of
///
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Types manipulated here have been marked earlier")]
+ [UnconditionalSuppressMessage("Trimming", "IL2041", Justification = "Types manipulated here have been marked earlier")]
internal static class JSObjectMetadataProvider
{
- private static readonly Func _getByReflection = t => new ReflectionMetadata(t);
+ private static readonly Func _getByReflection = (t) => new ReflectionMetadata(t);
+
static JSObjectMetadataProvider() => _getByReflection = _getByReflection.AsMemoized();
///
@@ -26,7 +30,9 @@ public static IJSObjectMetadata Get(Type type)
private class ReflectionMetadata : IJSObjectMetadata
{
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)]
private readonly Type _type;
+
private static long _handles;
private bool _isPrototypeExported;
@@ -35,7 +41,8 @@ private class ReflectionMetadata : IJSObjectMetadata
private static readonly char[] _parametersTrimArray = new char[] { '{', '}', ' ' };
private static readonly char[] _doubleQuoteSpaceArray = new[] { '"', ' ' };
- public ReflectionMetadata(Type type)
+ public ReflectionMetadata(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicMethods)] Type type)
{
_type = type;
}
diff --git a/src/Uno.Foundation.Runtime.WebAssembly/Interop/TSInteropMarshaller.wasm.cs b/src/Uno.Foundation.Runtime.WebAssembly/Interop/TSInteropMarshaller.wasm.cs
index 12ce918d236a..4876fe058ed1 100644
--- a/src/Uno.Foundation.Runtime.WebAssembly/Interop/TSInteropMarshaller.wasm.cs
+++ b/src/Uno.Foundation.Runtime.WebAssembly/Interop/TSInteropMarshaller.wasm.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text;
using Uno.Foundation;
@@ -164,13 +165,15 @@ public static StructPtr AllocateStructure(Type type)
return new StructPtr(Marshal.AllocHGlobal(size), type);
}
- public static T UnmarshalStructure(AutoPtr ptr)
+ public static T UnmarshalStructure<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(AutoPtr ptr)
where T : struct
{
return Marshal.PtrToStructure(ptr);
}
- public static T UnmarshalStructure(StructPtr ptr)
+ public static T UnmarshalStructure<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(StructPtr ptr)
where T : struct
{
return Marshal.PtrToStructure(ptr);
diff --git a/src/Uno.Foundation/Metadata/ApiInformation.cs b/src/Uno.Foundation/Metadata/ApiInformation.cs
index b75e79bfe3ce..5086652b7700 100644
--- a/src/Uno.Foundation/Metadata/ApiInformation.cs
+++ b/src/Uno.Foundation/Metadata/ApiInformation.cs
@@ -1,5 +1,6 @@
#nullable enable
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Uno.Foundation.Logging;
@@ -50,9 +51,11 @@ public static bool IsTypePresent(string typeName)
}
}
+ [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "GetMethod may return null, normal flow of operation")]
internal static bool IsMethodPresent(Type type, string methodName)
=> IsImplementedByUno(type?.GetMethod(methodName));
+ [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "GetField may return null, normal flow of operation")]
public static bool IsMethodPresent(string typeName, string methodName)
=> IsImplementedByUno(
GetValidType(typeName)
@@ -72,9 +75,11 @@ public static bool IsEventPresent(string typeName, string eventName)
GetValidType(typeName)
?.GetEvent(eventName));
+ [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "GetField may return null, normal flow of operation")]
internal static bool IsPropertyPresent(Type type, string methodName)
=> IsImplementedByUno(type?.GetProperty(methodName));
+ [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "GetProperty may return null, normal flow of operation")]
public static bool IsPropertyPresent(string typeName, string propertyName)
=> IsImplementedByUno(
GetValidType(typeName)
@@ -106,7 +111,11 @@ public static bool IsWriteablePropertyPresent(string typeName, string propertyNa
return false;
}
- public static bool IsEnumNamedValuePresent(string enumTypeName, string valueName)
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "GetField may return null, normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "GetField may return null, normal flow of operation")]
+ public static bool IsEnumNamedValuePresent(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] string enumTypeName,
+ string valueName)
=> GetValidType(enumTypeName)?.GetField(valueName) != null;
///
@@ -124,6 +133,7 @@ public static bool IsEnumNamedValuePresent(string enumTypeName, string valueName
///
public static LogLevel NotImplementedLogLevel { get; set; } = LogLevel.Debug;
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Types may be removed or not present as part of the normal operations of that method")]
private static Type? GetValidType(string typeName)
{
lock (_assemblies)
diff --git a/src/Uno.Foundation/SizeConverter.cs b/src/Uno.Foundation/SizeConverter.cs
index 26a7b19ecbb0..bdb6fffbcf38 100644
--- a/src/Uno.Foundation/SizeConverter.cs
+++ b/src/Uno.Foundation/SizeConverter.cs
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
@@ -10,6 +11,9 @@ internal class SizeConverter : TypeConverter
{
#if NETSTANDARD
private static readonly char[] _commaArray = new[] { ',' };
+#endif
+#if !NETSTANDARD
+ [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Size))]
#endif
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
@@ -23,6 +27,9 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT
return base.CanConvertFrom(context, sourceType);
}
+#if !NETSTANDARD
+ [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Size))]
+#endif
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var stringValue = value as string;
diff --git a/src/Uno.Foundation/Uno.Core.Extensions/Uno.Core.Extensions.Compatibility/Reflection/TypeExtensions.cs b/src/Uno.Foundation/Uno.Core.Extensions/Uno.Core.Extensions.Compatibility/Reflection/TypeExtensions.cs
index ad4ccdf9de29..d0e60c566754 100644
--- a/src/Uno.Foundation/Uno.Core.Extensions/Uno.Core.Extensions.Compatibility/Reflection/TypeExtensions.cs
+++ b/src/Uno.Foundation/Uno.Core.Extensions/Uno.Core.Extensions.Compatibility/Reflection/TypeExtensions.cs
@@ -16,6 +16,7 @@
// ******************************************************************
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
@@ -60,7 +61,12 @@ public static bool IsNullable(this Type type)
///
/// The generic type without generic type argument(s).
///
- public static bool IsGenericDescentOf(this Type type, Type genericTypeDefinition)
+ public static bool IsGenericDescentOf(
+#if NET9_0_OR_GREATER
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
+#endif
+ this Type type,
+ Type genericTypeDefinition)
{
if (!genericTypeDefinition.IsGenericTypeDefinition)
{
diff --git a/src/Uno.UI/DataBinding/BindingExpression.cs b/src/Uno.UI/DataBinding/BindingExpression.cs
index 6a57eb0b2eb7..ab25f08024a3 100644
--- a/src/Uno.UI/DataBinding/BindingExpression.cs
+++ b/src/Uno.UI/DataBinding/BindingExpression.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
@@ -840,6 +841,7 @@ private object ConvertValue(object value)
}
}
+ [UnconditionalSuppressMessage("Trimming", "IL2077", Justification = "Types manipulated here have been marked earlier")]
private object ConvertToBoundPropertyType(object value)
{
// _boundPropertyType can be null for properties not bound for the actual instance (no matching properties found)
diff --git a/src/Uno.UI/DataBinding/BindingPropertyHelper.FastConvert.cs b/src/Uno.UI/DataBinding/BindingPropertyHelper.FastConvert.cs
index a8e65e9805e2..8287e2c478b9 100644
--- a/src/Uno.UI/DataBinding/BindingPropertyHelper.FastConvert.cs
+++ b/src/Uno.UI/DataBinding/BindingPropertyHelper.FastConvert.cs
@@ -15,6 +15,8 @@
using System.Text.RegularExpressions;
using Microsoft.UI.Text;
using FontWeight = Windows.UI.Text.FontWeight;
+using System.Diagnostics.CodeAnalysis;
+
#if __ANDROID__
using View = Android.Views.View;
@@ -962,6 +964,7 @@ private static bool FastStringToUriConvert(Type outputType, string input, ref ob
}
}
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "GetType may return null, normal flow of operation")]
private static bool FastStringToTypeConvert(Type outputType, string input, ref object output)
{
if (outputType == typeof(Type))
diff --git a/src/Uno.UI/DataBinding/BindingPropertyHelper.cs b/src/Uno.UI/DataBinding/BindingPropertyHelper.cs
index 55dee76aa248..fc6cdba0ee41 100644
--- a/src/Uno.UI/DataBinding/BindingPropertyHelper.cs
+++ b/src/Uno.UI/DataBinding/BindingPropertyHelper.cs
@@ -39,6 +39,9 @@ public static IBindableMetadataProvider? Provider
}
}
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "normal flow of operation")]
internal static partial class BindingPropertyHelper
{
private static readonly Logger _log = typeof(BindingPropertyHelper).Log();
@@ -334,7 +337,10 @@ internal static ValueUnsetterHandler GetValueUnsetter(Type type, string property
/// The private members lookup is present to enable the binding to
/// x:Name elements in x:Bind operations.
///
- private static PropertyInfo? GetPropertyInfo(Type type, string name, bool allowPrivateMembers)
+ private static PropertyInfo? GetPropertyInfo(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] Type type,
+ string name,
+ bool allowPrivateMembers)
{
do
{
@@ -375,7 +381,10 @@ internal static ValueUnsetterHandler GetValueUnsetter(Type type, string property
/// The private members lookup is present to enable the binding to
/// x:Name elements in x:Bind operations.
///
- private static PropertyInfo? GetIndexerInfo(Type type, Type? parameterType, bool allowPrivateMembers)
+ private static PropertyInfo? GetIndexerInfo(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] Type type,
+ Type? parameterType,
+ bool allowPrivateMembers)
{
var parameterTypes = parameterType is not null
? new[] { parameterType }
@@ -412,7 +421,10 @@ internal static ValueUnsetterHandler GetValueUnsetter(Type type, string property
return null;
}
- private static FieldInfo? GetFieldInfo(Type type, string name, bool allowPrivateMembers)
+ private static FieldInfo? GetFieldInfo(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] Type type,
+ string name,
+ bool allowPrivateMembers)
{
do
{
@@ -482,6 +494,8 @@ private static string SanitizePropertyName(Type type, string property)
return property;
}
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "GetField/GetType may return null, normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2077", Justification = "GetField/GetType may return null, normal flow of operation")]
private static ValueGetterHandler InternalGetValueGetter(Type type, string property, bool allowPrivateMembers)
{
if (type == typeof(UnsetValue))
@@ -810,8 +824,11 @@ private static string CoerceIndexerParameter(string indexerParameter, Type? opti
return indexerParameter;
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "To be refactored"),
- System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "To be refactored")]
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "To be refactored")]
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "To be refactored")]
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "GetField/GetType may return null, normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2077", Justification = "GetField/GetType may return null, normal flow of operation")]
+
private static ValueSetterHandler InternalGetValueSetter(Type type, string property, bool convert, DependencyPropertyValuePrecedences precedence)
{
if (type == typeof(UnsetValue))
@@ -1105,10 +1122,10 @@ private static ValueUnsetterHandler InternalGetValueUnsetter(Type type, string p
return delegate { once(); };
}
- private static DependencyProperty FindDependencyProperty(Type ownerType, string property)
+ private static DependencyProperty FindDependencyProperty([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type ownerType, string property)
=> DependencyProperty.GetProperty(ownerType, property);
- private static DependencyProperty? FindAttachedProperty(Type type, string property)
+ private static DependencyProperty? FindAttachedProperty([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type type, string property)
{
var propertyInfo = DependencyPropertyDescriptor.Parse(property);
if (propertyInfo != null)
@@ -1154,7 +1171,7 @@ private static DependencyProperty FindDependencyProperty(Type ownerType, string
.FirstOrDefault();
}
- private static object? ConvertToEnum(Type enumType, object value)
+ private static object? ConvertToEnum([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type enumType, object value)
{
var valueString = Enum.GetName(enumType, value);
@@ -1212,7 +1229,9 @@ private static DependencyProperty FindDependencyProperty(Type ownerType, string
}
}
- private static object? ConvertUsingTypeDescriptor(Type type, object value)
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Types may be removed or not present as part of the normal operations of that method")]
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "Types may be removed or not present as part of the normal operations of that method")]
+ private static object? ConvertUsingTypeDescriptor([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, object value)
{
var valueTypeConverter = TypeDescriptor.GetConverter(value.GetType());
if (valueTypeConverter.CanConvertTo(type))
@@ -1275,7 +1294,9 @@ private static DependencyProperty FindDependencyProperty(Type ownerType, string
return value;
}
- internal static object? Convert(Type? propertyType, object? value)
+ internal static object? Convert(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? propertyType,
+ object? value)
{
if (value != null)
{
diff --git a/src/Uno.UI/Extensions/UIElementExtensions.cs b/src/Uno.UI/Extensions/UIElementExtensions.cs
index e19c07b58c81..b6014724d76c 100644
--- a/src/Uno.UI/Extensions/UIElementExtensions.cs
+++ b/src/Uno.UI/Extensions/UIElementExtensions.cs
@@ -8,6 +8,7 @@
using Uno.Extensions;
using Uno.Foundation.Logging;
using System.Globalization;
+using System.Diagnostics.CodeAnalysis;
namespace Uno.UI.Extensions;
@@ -82,6 +83,7 @@ internal static bool SetBorderThickness(this UIElement uiElement, Thickness bord
private static Dictionary<(Type type, string property), DependencyProperty?>? _dependencyPropertyReflectionCache;
+ [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "The provided type has been marked before getting at that location")]
internal static DependencyProperty? FindDependencyPropertyUsingReflection(this UIElement uiElement, string propertyName)
{
var type = uiElement.GetType();
diff --git a/src/Uno.UI/Helpers/TypeMappings.cs b/src/Uno.UI/Helpers/TypeMappings.cs
index 2da4cce7f6b2..c3a8101045f0 100644
--- a/src/Uno.UI/Helpers/TypeMappings.cs
+++ b/src/Uno.UI/Helpers/TypeMappings.cs
@@ -44,7 +44,8 @@ public static class TypeMappings
///
/// This is the type that may have been replaced
/// If instanceType has been replaced, then the replacement type, otherwise the instanceType
- public static Type GetReplacementType(this Type instanceType)
+ public static Type GetReplacementType(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] this Type instanceType)
{
// Two scenarios:
// 1. The instance type is a mapped type, in which case we need to get the original type
@@ -58,6 +59,7 @@ public static Type GetReplacementType(this Type instanceType)
///
/// The original type to be created
/// An new instance for the original type
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
public static object CreateInstance<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOriginalType>()
=> Activator.CreateInstance(typeof(TOriginalType).GetReplacementType());
diff --git a/src/Uno.UI/LinkerDefinition.Wasm.xml b/src/Uno.UI/LinkerDefinition.Wasm.xml
index 7834813d4da0..2e38c6b5a6f3 100644
--- a/src/Uno.UI/LinkerDefinition.Wasm.xml
+++ b/src/Uno.UI/LinkerDefinition.Wasm.xml
@@ -7,7 +7,6 @@
-
@@ -95,11 +94,6 @@
-
-
-
-
-
diff --git a/src/Uno.UI/Microsoft/UI/Xaml/Controls/Expander/ExpanderAutomationPeer.cs b/src/Uno.UI/Microsoft/UI/Xaml/Controls/Expander/ExpanderAutomationPeer.cs
index 1fb474caf2d8..a9f89badb615 100644
--- a/src/Uno.UI/Microsoft/UI/Xaml/Controls/Expander/ExpanderAutomationPeer.cs
+++ b/src/Uno.UI/Microsoft/UI/Xaml/Controls/Expander/ExpanderAutomationPeer.cs
@@ -187,7 +187,7 @@ internal void RaiseExpandCollapseAutomationEvent(ExpandCollapseState newState)
// Uno Doc: AutomationEvents not currently implemented so added an API check
// if (winrt::AutomationPeer::ListenerExists(winrt::AutomationEvents::PropertyChanged))
if (ApiInformation.IsEnumNamedValuePresent(
- "Microsoft.UI.Xaml.Automation.Peers.AutomationEvents",
+ "Microsoft.UI.Xaml.Automation.Peers.AutomationEvents, Uno.UI",
nameof(AutomationEvents.PropertyChanged)) && ListenerExists(AutomationEvents.PropertyChanged))
{
ExpandCollapseState oldState = (newState == ExpandCollapseState.Expanded) ?
diff --git a/src/Uno.UI/UI/Xaml/Controls/Control/Control.cs b/src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
index af4264ee7983..a06c5d0cfa88 100644
--- a/src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/Control/Control.cs
@@ -11,6 +11,8 @@
using Uno;
using Uno.UI.Xaml.Core;
using Uno.UI.Xaml.Input;
+using System.Diagnostics.CodeAnalysis;
+
#if __ANDROID__
using View = Android.Views.View;
using ViewGroup = Android.Views.ViewGroup;
@@ -284,6 +286,7 @@ private protected override void OnPostLoading()
}
#endif
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
private void SubscribeToOverridenRoutedEvents()
{
// Overridden Events are registered from constructor to ensure they are
@@ -1095,7 +1098,9 @@ protected virtual void OnLostFocus(RoutedEventArgs e) { }
private static readonly Type[] _manipInertiaArgsType = new[] { typeof(ManipulationInertiaStartingRoutedEventArgs) };
private static readonly Type[] _manipCompletedArgsType = new[] { typeof(ManipulationCompletedRoutedEventArgs) };
- internal static RoutedEventFlag EvaluateImplementedControlRoutedEvents(Type type)
+ internal static RoutedEventFlag EvaluateImplementedControlRoutedEvents(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
+ Type type)
{
var result = RoutedEventFlag.None;
diff --git a/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs b/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs
index 569f57515586..bc080aefa5d9 100644
--- a/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -163,7 +164,10 @@ public void SetNavigationState(string navigationState, bool suppressNavigate)
}
}
- internal static object CreatePageInstance(Type sourcePageType)
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
+ internal static object CreatePageInstance(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
+ Type sourcePageType)
{
var replacementType = sourcePageType.GetReplacementType(); // Get latest replacement type to handle Hot Reload.
if (Uno.UI.DataBinding.BindingPropertyHelper.BindableMetadataProvider != null)
diff --git a/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.legacy.cs b/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.legacy.cs
index 66f636f91087..75021ad1ecbc 100644
--- a/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.legacy.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.legacy.cs
@@ -16,6 +16,7 @@
using Uno.UI.Xaml.Core;
using Uno.UI.Helpers;
using Uno.Foundation.Logging;
+using System.Diagnostics.CodeAnalysis;
namespace Microsoft.UI.Xaml.Controls;
@@ -104,6 +105,8 @@ private void GoForwardLegacy()
private bool NavigateLegacy(Type sourcePageType, object parameter) => Navigate(sourcePageType, parameter, null);
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Types manipulated here have been marked earlier")]
private bool NavigateWithTransitionInfoLegacy(Type sourcePageType, object parameter, NavigationTransitionInfo infoOverride)
{
var entry = new PageStackEntry(sourcePageType.GetReplacementType(), parameter, infoOverride);
diff --git a/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.partial.mux.cs b/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.partial.mux.cs
index e45087d49c50..62c984ab4e48 100644
--- a/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.partial.mux.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/Frame/Frame.partial.mux.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using DirectUI;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media.Animation;
@@ -689,6 +690,7 @@ private void RaiseNavigating(
//TraceFrameNavigatingInfo(WindowsGetStringRawBuffer(descriptor, null), (unsigned char)(navigationMode));
}
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "normal flow of operations")]
private void RaiseNavigationFailed(string descriptor, Exception errorResult, out bool isCanceled)
{
if (descriptor is null)
diff --git a/src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsControl.cs b/src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsControl.cs
index 0ecdb0577cd5..e33e656a7ce3 100644
--- a/src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsControl.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsControl.cs
@@ -17,6 +17,8 @@
using Uno.UI.DataBinding;
using Uno.UI.Extensions;
using System.Runtime.InteropServices.JavaScript;
+using System.Diagnostics.CodeAnalysis;
+
#if __ANDROID__
@@ -651,6 +653,7 @@ protected virtual void OnItemsSourceChanged(DependencyPropertyChangedEventArgs e
TryObserveCollectionViewSource(e.NewValue);
}
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
private void TrySnapshotNonObservableSource(object source)
{
// For normal enumerables, that are not notifying (INCC) or observable (ObsCollection),
diff --git a/src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs b/src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs
index b37c5ecb6d5d..b32ef85a41f9 100644
--- a/src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs
+++ b/src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs
@@ -414,6 +414,8 @@ internal void SetTemplateBinding(DependencyProperty targetProperty, DependencyPr
///
/// Finds a DependencyProperty for the specified C# property
///
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Types manipulated here have been marked earlier")]
private DependencyProperty? FindStandardProperty(Type originalObjectType, string dependencyProperty, bool allowPrivateMembers)
{
var propertyType = BindingPropertyHelper.GetPropertyType(originalObjectType, dependencyProperty, allowPrivateMembers);
diff --git a/src/Uno.UI/UI/Xaml/DependencyObjectStore.cs b/src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
index 2ae3958d1fd1..54e44e504678 100644
--- a/src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
+++ b/src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
@@ -18,6 +18,8 @@
using System.Globalization;
using Windows.ApplicationModel.Calls;
using Microsoft.UI.Xaml.Controls;
+using System.Diagnostics.CodeAnalysis;
+
#if __ANDROID__
@@ -185,6 +187,7 @@ internal void ClonePropertiesToAnotherStoreForHotReload(DependencyObjectStore ot
/// Creates a delegated dependency object instance for the specified
///
///
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "normal flow of operation")]
public DependencyObjectStore(object originalObject, DependencyProperty dataContextProperty)
{
_originalObjectRef = WeakReferencePool.RentWeakReference(this, originalObject);
@@ -1498,6 +1501,8 @@ private void InnerUpdateResourceBindingsUnsafe(ResourceUpdateReason updateReason
}
}
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "normal flow of operation")]
private void SetResourceBindingValue(DependencyProperty property, ResourceBinding binding, object? value)
{
var convertedValue = BindingPropertyHelper.Convert(property.Type, value);
diff --git a/src/Uno.UI/UI/Xaml/DependencyProperty.cs b/src/Uno.UI/UI/Xaml/DependencyProperty.cs
index e89e4d5ebfa0..a769ad8eceb4 100644
--- a/src/Uno.UI/UI/Xaml/DependencyProperty.cs
+++ b/src/Uno.UI/UI/Xaml/DependencyProperty.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
@@ -137,7 +138,11 @@ internal bool IsDependencyObjectCollection
/// The metadata to use when creating the property
/// A dependency property instance
/// A property with the same name has already been declared for the ownerType
- public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata)
+ public static DependencyProperty Register(
+ string name,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type propertyType,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type ownerType,
+ PropertyMetadata typeMetadata)
{
typeMetadata = FixMetadataIfNeeded(propertyType, typeMetadata);
@@ -158,7 +163,10 @@ public static DependencyProperty Register(string name, Type propertyType, Type o
return newProperty;
}
- private static PropertyMetadata FixMetadataIfNeeded(Type propertyType, PropertyMetadata metadata)
+ private static PropertyMetadata FixMetadataIfNeeded(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
+ Type propertyType,
+ PropertyMetadata metadata)
{
if (metadata is null)
{
@@ -186,7 +194,11 @@ private static PropertyMetadata FixMetadataIfNeeded(Type propertyType, PropertyM
/// This method is to ensure that all uno controls defined dependency properties are using .
/// This is achieved by banning the other public overload in Uno.UI directory.
///
- internal static DependencyProperty Register(string name, Type propertyType, Type ownerType, FrameworkPropertyMetadata typeMetadata)
+ internal static DependencyProperty Register(
+ string name,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type propertyType,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type ownerType,
+ FrameworkPropertyMetadata typeMetadata)
#pragma warning disable RS0030 // Do not used banned APIs
=> Register(name, propertyType, ownerType, (PropertyMetadata)typeMetadata);
#pragma warning restore RS0030 // Do not used banned APIs
@@ -200,7 +212,11 @@ internal static DependencyProperty Register(string name, Type propertyType, Type
/// The metadata to use when creating the property
/// A dependency property instance
/// A property with the same name has already been declared for the ownerType
- public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata)
+ public static DependencyProperty RegisterAttached(
+ string name,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type propertyType,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type ownerType,
+ PropertyMetadata defaultMetadata)
{
defaultMetadata = FixMetadataIfNeeded(propertyType, defaultMetadata);
@@ -234,6 +250,7 @@ public static DependencyProperty RegisterAttached(string name, Type propertyType
/// This method is to ensure that all uno controls defined dependency properties are using .
/// This is achieved by banning the other public overload in Uno.UI directory.
///
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Types manipulated here have been marked earlier")]
internal static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, FrameworkPropertyMetadata typeMetadata)
#pragma warning disable RS0030 // Do not used banned APIs
=> RegisterAttached(name, propertyType, ownerType, (PropertyMetadata)typeMetadata);
@@ -416,6 +433,7 @@ private static void RegisterProperty(Type ownerType, string name, DependencyProp
///
/// See: http://stackoverflow.com/questions/6729841/why-did-the-beforefieldinit-behavior-change-in-net-4
///
+ [UnconditionalSuppressMessage("Trimming", "IL2059", Justification = "Normal flow of operations")]
internal static void ForceInitializeTypeConstructor(Type type)
{
do
diff --git a/src/Uno.UI/UI/Xaml/DependencyPropertyDescriptor.cs b/src/Uno.UI/UI/Xaml/DependencyPropertyDescriptor.cs
index 6db8dd3f59e0..f6ac54e111c6 100644
--- a/src/Uno.UI/UI/Xaml/DependencyPropertyDescriptor.cs
+++ b/src/Uno.UI/UI/Xaml/DependencyPropertyDescriptor.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Uno.Extensions;
using Uno.Foundation.Logging;
@@ -92,7 +93,12 @@ internal static DependencyPropertyDescriptor Parse(string propertyPath)
/// This method is split to avoid Type.GetType causing fallbacks
/// on the Wasm interpreter.
///
+ [UnconditionalSuppressMessage(
+ "AssemblyLoadTrimming",
+ "IL2026:RequiresUnreferencedCode",
+ Justification = "Types may be removed or not present as part of the normal operations of that method")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "GetType may return null, normal flow of operations")]
private static Type SearchTypeInLoadedAssemblies(string qualifiedTypeName)
{
// If not available, search through Reflection
diff --git a/src/Uno.UI/UI/Xaml/HtmlElementHelper.wasm.cs b/src/Uno.UI/UI/Xaml/HtmlElementHelper.wasm.cs
index 833067ab9e4e..51ba315ac12e 100644
--- a/src/Uno.UI/UI/Xaml/HtmlElementHelper.wasm.cs
+++ b/src/Uno.UI/UI/Xaml/HtmlElementHelper.wasm.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Uno.Core.Comparison;
@@ -16,6 +17,8 @@ internal static class HtmlElementHelper
private static readonly PropertyInfo _htmlElementAttributeTagGetter;
private static readonly Assembly _unoUIAssembly = typeof(UIElement).Assembly;
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "HtmlElementAttribute is suppressed from the linker")]
+ [UnconditionalSuppressMessage("Trimming", "IL2080", Justification = "HtmlElementAttribute is suppressed from the linker")]
static HtmlElementHelper()
{
_htmlElementAttribute = GetUnoUIRuntimeWebAssembly().GetType("Uno.UI.Runtime.WebAssembly.HtmlElementAttribute", true)!;
diff --git a/src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs b/src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs
index a6ee7c8f43a4..c3f2abf431ff 100644
--- a/src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs
+++ b/src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs
@@ -30,6 +30,10 @@
namespace Microsoft.UI.Xaml.Markup.Reader
{
+ [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "Normal flow of operations")]
+ [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Normal flow of operations")]
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Normal flow of operations")]
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Normal flow of operations")]
internal partial class XamlObjectBuilder
{
private XamlFileDefinition _fileDefinition;
@@ -138,7 +142,7 @@ void TrySetContextualProperties(object? instance, XamlObjectDefinition control)
if (type == null)
{
- throw new InvalidOperationException($"Unable to find type {control.Type}");
+ throw new InvalidOperationException($"Unable to find type {control.Type}. If the linker is enabled, more info at https://aka.platform.uno/XXX");
}
var unknownContent = control.Members.Where(m => m.Member.Name == "_UnknownContent").FirstOrDefault();
diff --git a/src/Uno.UI/UI/Xaml/Markup/Reader/XamlTypeResolver.cs b/src/Uno.UI/UI/Xaml/Markup/Reader/XamlTypeResolver.cs
index 9420ac397b9e..ffe698277383 100644
--- a/src/Uno.UI/UI/Xaml/Markup/Reader/XamlTypeResolver.cs
+++ b/src/Uno.UI/UI/Xaml/Markup/Reader/XamlTypeResolver.cs
@@ -11,9 +11,13 @@
using Uno.Xaml;
using Windows.UI;
using Windows.Foundation;
+using System.Diagnostics.CodeAnalysis;
namespace Microsoft.UI.Xaml.Markup.Reader
{
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2075znote", Justification = "normal flow of operation")]
internal class XamlTypeResolver
{
private readonly static Assembly[] _lookupAssemblies = new[]{
@@ -199,7 +203,8 @@ public bool IsInitializedCollection(PropertyInfo property)
) as DependencyProperty;
}
- private static IEnumerable GetAllProperties(Type? type)
+ private static IEnumerable GetAllProperties(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] Type? type)
{
Type? currentType = type;
@@ -214,7 +219,10 @@ private static IEnumerable GetAllProperties(Type? type)
}
}
- private static IEnumerable GetAllFields(Type? type)
+ [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "GetField/BaseType may return null, normal flow of operation")]
+ [UnconditionalSuppressMessage("Trimming", "IL2070", Justification = "GetField/BaseType may return null, normal flow of operation")]
+ private static IEnumerable GetAllFields(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] Type? type)
{
Type? currentType = type;
@@ -245,8 +253,10 @@ public bool IsCollectionOrListType(Type? type)
IsImplementingInterface(type, typeof(global::System.Collections.Generic.IList<>));
}
- private bool IsImplementingInterface(Type type, Type iface) =>
- type
+ private bool IsImplementingInterface(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type,
+ Type iface)
+ => type
.Flatten(t => t.BaseType!)
.Any(t => t
.GetInterfaces()
@@ -331,6 +341,8 @@ string getFullName()
}
}
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Types may be removed or not present as part of the normal operations of that method")]
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "GetType may return null, normal flow of operation")]
private Type? SourceFindType(string? name)
{
static string? GetFullyQualifiedName(NamespaceDeclaration? ns, string nonQualifiedName)
@@ -407,13 +419,16 @@ string getFullName()
// As a partial name using the non-qualified name
() => Type.GetType(originalName.Split(':').ElementAtOrDefault(1) ?? ""),
-
+
// Look for the type in all loaded assemblies
() => AppDomain.CurrentDomain
.GetAssemblies()
- .Select(a =>
- (name != null ? a.GetType(name) : null) ??
- a.GetType(originalName)
+ .Select(
+
+ [UnconditionalSuppressMessage("Trimming","IL2026", Justification = "Types may be removed or not present as part of the normal operations of that method")]
+ (a) =>
+ (name != null ? a.GetType(name) : null) ??
+ a.GetType(originalName)
)
.Trim()
.FirstOrDefault(),
@@ -507,6 +522,7 @@ private static bool SourceIsAttachedProperty(Type type, string name)
public Type? FindPropertyType(string ownerType, string propertyName) => _findPropertyTypeByName(ownerType, propertyName);
+ [UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Types manipulated here have been marked earlier")]
private Type? SourceFindPropertyType(string ownerType, string propertyName)
{
var type = FindType(ownerType);
diff --git a/src/Uno.UI/UI/Xaml/Markup/XamlBindingHelper.cs b/src/Uno.UI/UI/Xaml/Markup/XamlBindingHelper.cs
index e3aecc9f352f..0c5b93bc403f 100644
--- a/src/Uno.UI/UI/Xaml/Markup/XamlBindingHelper.cs
+++ b/src/Uno.UI/UI/Xaml/Markup/XamlBindingHelper.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using Uno;
using Uno.Extensions;
using Uno.Foundation.Logging;
@@ -18,8 +19,10 @@ public sealed partial class XamlBindingHelper
///
/// Converts a value from a source type to a target type.
///
- public static object ConvertValue(Type type, object value) =>
- Uno.UI.DataBinding.BindingPropertyHelper.Convert(type, value);
+ public static object ConvertValue(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type,
+ object value)
+ => Uno.UI.DataBinding.BindingPropertyHelper.Convert(type, value);
///
/// Resumes rendering of the specified element.
diff --git a/src/Uno.UI/UI/Xaml/Navigation/NavigationCache.mux.cs b/src/Uno.UI/UI/Xaml/Navigation/NavigationCache.mux.cs
index 9b6dd0c3ee1a..9fdb8e74071d 100644
--- a/src/Uno.UI/UI/Xaml/Navigation/NavigationCache.mux.cs
+++ b/src/Uno.UI/UI/Xaml/Navigation/NavigationCache.mux.cs
@@ -13,6 +13,7 @@
// determine which content to replace.
using System;
+using System.Diagnostics.CodeAnalysis;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
@@ -77,6 +78,7 @@ internal object GetContent(PageStackEntry pPageStackEntry)
//TraceNavigationCacheGetContentInfo(WindowsGetStringRawBuffer(strDescriptor, null), found);
}
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "The provided type has been marked before getting at that location")]
private object LoadContent(string descriptor)
{
var type = Type.GetType(descriptor);
diff --git a/src/Uno.UI/UI/Xaml/Navigation/NavigationHelpers.cs b/src/Uno.UI/UI/Xaml/Navigation/NavigationHelpers.cs
index d94a7e9a9d11..3277a6226205 100644
--- a/src/Uno.UI/UI/Xaml/Navigation/NavigationHelpers.cs
+++ b/src/Uno.UI/UI/Xaml/Navigation/NavigationHelpers.cs
@@ -3,6 +3,7 @@
// MUX Reference dxaml\xcp\dxaml\lib\NavigationHelpers.cpp, tag winui3/release/1.5.5, commit fd8e26f1d
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using Microsoft.UI.Xaml.Media.Animation;
@@ -15,6 +16,7 @@ namespace DirectUI;
internal static class NavigationHelpers
{
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "The provided type has been marked before getting at that location")]
internal static NavigationEventArgs CreateINavigationEventArgs(
object content,
object parameter,
@@ -40,6 +42,7 @@ internal static NavigationEventArgs CreateINavigationEventArgs(
return spNavigationEventArgs;
}
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "The provided type has been marked before getting at that location")]
internal static NavigatingCancelEventArgs CreateINavigatingCancelEventArgs(
object parameter,
NavigationTransitionInfo pTransitionInfo,
diff --git a/src/Uno.UI/UI/Xaml/Navigation/NavigationHistory.mux.cs b/src/Uno.UI/UI/Xaml/Navigation/NavigationHistory.mux.cs
index 29dba43ed12a..fccd69916c75 100644
--- a/src/Uno.UI/UI/Xaml/Navigation/NavigationHistory.mux.cs
+++ b/src/Uno.UI/UI/Xaml/Navigation/NavigationHistory.mux.cs
@@ -14,6 +14,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Animation;
@@ -162,6 +163,7 @@ internal NavigationMode GetPendingNavigationMode()
internal NavigationMode GetCurrentNavigationMode() => m_navigationMode;
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "Types manipulated here have been marked earlier")]
internal void CommitNavigation()
{
int nCount = 0;
diff --git a/src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.cs b/src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.cs
index 7fa6d4368298..cdd74d11fba3 100644
--- a/src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.cs
+++ b/src/Uno.UI/UI/Xaml/Navigation/PageStackEntry.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Animation;
using Uno.UI.DataBinding;
@@ -39,6 +40,7 @@ private PageStackEntry()
InitializeBinder();
}
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "The provided type has been marked before getting at that location")]
internal static PageStackEntry Create(
Frame frame,
string descriptor,
diff --git a/src/Uno.UI/UI/Xaml/PagePool.cs b/src/Uno.UI/UI/Xaml/PagePool.cs
index eb224545a2ee..7e1b8eb4cfd8 100644
--- a/src/Uno.UI/UI/Xaml/PagePool.cs
+++ b/src/Uno.UI/UI/Xaml/PagePool.cs
@@ -8,6 +8,7 @@
using Uno.UI;
using Windows.UI.Core;
using Microsoft.UI.Xaml.Controls;
+using System.Diagnostics.CodeAnalysis;
namespace Microsoft.UI.Xaml
{
@@ -15,6 +16,8 @@ namespace Microsoft.UI.Xaml
/// Provides an instance pool for s. Pooling is enabled when is set to true.
///
/// Enabling page pooling improves performance when using navigation.
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "Types manipulated here have been marked earlier")]
+ [UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "Types manipulated here have been marked earlier")]
public class PagePool
{
private readonly Stopwatch _watch = new Stopwatch();
diff --git a/src/Uno.UI/UI/Xaml/ResourceResolver.cs b/src/Uno.UI/UI/Xaml/ResourceResolver.cs
index 93ee027235ba..e656b9548fb2 100644
--- a/src/Uno.UI/UI/Xaml/ResourceResolver.cs
+++ b/src/Uno.UI/UI/Xaml/ResourceResolver.cs
@@ -14,6 +14,7 @@
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Resources;
+using System.Diagnostics.CodeAnalysis;
namespace Uno.UI
{
@@ -82,7 +83,10 @@ public static T ResolveResourceStatic(object key, object context = null)
/// Performs a one-time, typed resolution of a named resource, using Application.Resources.
///
[EditorBrowsable(EditorBrowsableState.Never)]
- public static object ResolveResourceStatic(object key, Type type, object context = null)
+ public static object ResolveResourceStatic(
+ object key,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type,
+ object context = null)
{
if (TryStaticRetrieval(new SpecializedResourceDictionary.ResourceKey(key), context, out var value))
{
@@ -289,6 +293,7 @@ public static void ApplyResource(DependencyObject owner, DependencyProperty prop
ApplyResource(owner, property, new SpecializedResourceDictionary.ResourceKey(resourceKey), updateReason, context, null);
}
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
internal static void ApplyResource(DependencyObject owner, DependencyProperty property, SpecializedResourceDictionary.ResourceKey specializedKey, ResourceUpdateReason updateReason, object context, DependencyPropertyValuePrecedences? precedence)
{
// If the invocation comes from XAML and from theme resources, resolution
diff --git a/src/Uno.UI/UI/Xaml/ResourceResolverSingleton.cs b/src/Uno.UI/UI/Xaml/ResourceResolverSingleton.cs
index 7c7df0f5e948..1429b300d798 100644
--- a/src/Uno.UI/UI/Xaml/ResourceResolverSingleton.cs
+++ b/src/Uno.UI/UI/Xaml/ResourceResolverSingleton.cs
@@ -11,6 +11,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Resources;
+using System.Diagnostics.CodeAnalysis;
namespace Uno.UI
{
@@ -29,7 +30,10 @@ public static ResourceResolverSingleton Instance
=> _instance ??= new ResourceResolverSingleton();
[EditorBrowsable(EditorBrowsableState.Never)]
- public object ResolveResourceStatic(object key, Type type, object context)
+ public object ResolveResourceStatic(
+ object key,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type,
+ object context)
=> ResourceResolver.ResolveResourceStatic(key, type, context);
[EditorBrowsable(EditorBrowsableState.Never)]
diff --git a/src/Uno.UI/UI/Xaml/Setter.cs b/src/Uno.UI/UI/Xaml/Setter.cs
index 4fd65a4184f6..29f60269cf64 100644
--- a/src/Uno.UI/UI/Xaml/Setter.cs
+++ b/src/Uno.UI/UI/Xaml/Setter.cs
@@ -13,6 +13,7 @@
using Windows.Foundation;
using Windows.Foundation.Metadata;
using Microsoft.UI.Xaml.Data;
+using System.Diagnostics.CodeAnalysis;
namespace Microsoft.UI.Xaml
{
@@ -133,6 +134,7 @@ public Setter(TargetPropertyPath targetPath, object value)
Value = value;
}
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
internal override void ApplyTo(DependencyObject o)
{
if (Property != null)
@@ -173,6 +175,7 @@ internal void ApplyValue(IFrameworkElement owner)
}
}
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
internal override bool TryGetSetterValue(out object? value, DependencyObject _)
{
if (ThemeResourceKey.HasValue)
diff --git a/src/Uno.UI/UI/Xaml/UIElement.cs b/src/Uno.UI/UI/Xaml/UIElement.cs
index c2a0ba2d5e8d..9015f2d5c3bb 100644
--- a/src/Uno.UI/UI/Xaml/UIElement.cs
+++ b/src/Uno.UI/UI/Xaml/UIElement.cs
@@ -35,6 +35,8 @@
using Microsoft.UI.Input;
using Uno.UI.Xaml.Media;
using Uno.UI.Xaml.Core.Scaling;
+using System.Diagnostics.CodeAnalysis;
+
#if __IOS__
using UIKit;
@@ -121,6 +123,7 @@ private bool ShouldMirrorVisual()
}
#endif
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
private void SubscribeToOverridenRoutedEvents()
{
// Overridden Events are registered from constructor to ensure they are
@@ -135,7 +138,9 @@ private void SubscribeToOverridenRoutedEvents()
}
}
- internal static RoutedEventFlag GetImplementedRoutedEventsForType(Type type)
+ internal static RoutedEventFlag GetImplementedRoutedEventsForType(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
+ Type type)
{
if (UIElementGeneratedProxy.TryGetImplementedRoutedEvents(type, out var result))
{
@@ -164,7 +169,9 @@ internal static RoutedEventFlag GetImplementedRoutedEventsForType(Type type)
return implementedRoutedEvents;
}
- internal static RoutedEventFlag EvaluateImplementedUIElementRoutedEvents(Type type)
+ internal static RoutedEventFlag EvaluateImplementedUIElementRoutedEvents(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
+ Type type)
{
RoutedEventFlag result = RoutedEventFlag.None;
@@ -181,7 +188,11 @@ private protected virtual void OnChildDesiredSizeChanged(UIElement child)
InvalidateMeasure();
}
- private protected static bool GetIsEventOverrideImplemented(Type type, string name, Type[] args)
+ private protected static bool GetIsEventOverrideImplemented(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
+ Type type,
+ string name,
+ Type[] args)
{
var method = type
.GetMethod(
@@ -1005,6 +1016,8 @@ internal static object GetDependencyPropertyValueInternal(DependencyObject owner
/// parameters passing on iOS, where the number of parameters follows a unconventional set of rules. Using
/// a single parameter with a simple delimitation format fits all platforms with little overhead.
///
+ [UnconditionalSuppressMessage("Trimming", "IL2077", Justification = "Types manipulated here have been marked earlier")]
+ [UnconditionalSuppressMessage("Trimming", "IL2072", Justification = "Types manipulated here have been marked earlier")]
internal static string SetDependencyPropertyValueInternal(DependencyObject owner, string dependencyPropertyNameAndValue)
{
var s = dependencyPropertyNameAndValue;
diff --git a/src/Uno.UWP/Storage/DataTypeSerializer.cs b/src/Uno.UWP/Storage/DataTypeSerializer.cs
index 726dc49b2592..039dfa043572 100644
--- a/src/Uno.UWP/Storage/DataTypeSerializer.cs
+++ b/src/Uno.UWP/Storage/DataTypeSerializer.cs
@@ -2,10 +2,15 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Text.Json;
+using System.Text.Json.Serialization;
using Uno.Extensions.Specialized;
+using Uno.Helpers.Serialization;
+using Uno.Storage.Internal;
+using Uno.Storage.Pickers.Internal;
namespace Windows.Storage;
@@ -68,6 +73,7 @@ public static string Serialize(object value)
return value.GetType().FullName + ":" + serializedValue;
}
+ [UnconditionalSuppressMessage("Trimming", "IL2057", Justification = "GetType may return null, normal flow of operation")]
public static object? Deserialize(string? value)
{
if (value is null)
@@ -122,12 +128,12 @@ private static string SerializeCompositeValue(ApplicationDataCompositeValue comp
targetDictionary.Add(entry.Key, serializedValue);
}
- return JsonSerializer.Serialize(targetDictionary);
+ return JsonHelper.Serialize(targetDictionary, DataTypeSerializerContext.Default);
}
private static ApplicationDataCompositeValue DeserializeCompositeValue(string value)
{
- var dictionary = JsonSerializer.Deserialize>(value);
+ var dictionary = JsonHelper.Deserialize>(value, DataTypeSerializerContext.Default);
if (dictionary is null)
{
throw new InvalidOperationException("Failed to deserialize ApplicationDataCompositeValue");
@@ -145,3 +151,8 @@ private static ApplicationDataCompositeValue DeserializeCompositeValue(string va
return composite;
}
}
+
+[JsonSerializable(typeof(Dictionary))]
+internal partial class DataTypeSerializerContext : JsonSerializerContext
+{
+}