From a36ceaebdf9367236731ca30a626707bb41fd379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Rozs=C3=ADval?= Date: Tue, 16 Jan 2024 17:06:54 +0100 Subject: [PATCH] [Trimming] Fix several trimming warnings (#19402) * Get converter type from attribute with correct annotations * Disable hot reload helper when it's not supported * Fix trim analysis warning in ResourceDictionary * Fix warning in DependencyService * Suppress warning IL2111 when creating RouteProperty * Fix BindableProperty ReturnType warnings * Update src/Controls/src/Core/Routing.cs Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com> * Remove fixed warnings from tests * Simplify DependencyType --------- Co-authored-by: Vitek Karas <10670590+vitek-karas@users.noreply.github.com> --- src/Controls/src/Core/BindableProperty.cs | 16 ++-- src/Controls/src/Core/DependencyService.cs | 31 +++--- .../src/Core/Internals/CellExtensions.cs | 12 ++- src/Controls/src/Core/ItemsView.cs | 2 +- src/Controls/src/Core/ResourceDictionary.cs | 2 +- src/Controls/src/Core/Routing.cs | 11 ++- src/Controls/src/Core/TemplatedItemsList.cs | 2 +- .../src/Core/Xaml/TypeConversionExtensions.cs | 23 ++--- src/Core/src/HotReload/HotReloadHelper.cs | 18 ++-- .../Utilities/BuildWarningsUtilities.cs | 94 ------------------- 10 files changed, 65 insertions(+), 146 deletions(-) diff --git a/src/Controls/src/Core/BindableProperty.cs b/src/Controls/src/Core/BindableProperty.cs index 84be6078ec60..d80b875d7ee7 100644 --- a/src/Controls/src/Core/BindableProperty.cs +++ b/src/Controls/src/Core/BindableProperty.cs @@ -18,6 +18,7 @@ namespace Microsoft.Maui.Controls public sealed class BindableProperty { internal const DynamicallyAccessedMemberTypes DeclaringTypeMembers = DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicMethods; + internal const DynamicallyAccessedMemberTypes ReturnTypeMembers = DynamicallyAccessedMemberTypes.PublicParameterlessConstructor; public delegate void BindingPropertyChangedDelegate(BindableObject bindable, object oldValue, object newValue); @@ -70,7 +71,7 @@ public sealed class BindableProperty /// public static readonly object UnsetValue = new object(); - BindableProperty(string propertyName, Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, + BindableProperty(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, BindablePropertyBindingChanging bindingChanging = null, bool isReadOnly = false, CreateDefaultValueDelegate defaultValueCreator = null) { @@ -125,6 +126,7 @@ public sealed class BindableProperty public string PropertyName { get; } /// + [DynamicallyAccessedMembers(ReturnTypeMembers)] public Type ReturnType { get; } internal BindablePropertyBindingChanging BindingChanging { get; private set; } @@ -140,7 +142,7 @@ public sealed class BindableProperty internal ValidateValueDelegate ValidateValue { get; private set; } /// - public static BindableProperty Create(string propertyName, Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue = null, BindingMode defaultBindingMode = BindingMode.OneWay, + public static BindableProperty Create(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue = null, BindingMode defaultBindingMode = BindingMode.OneWay, ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) { @@ -149,7 +151,7 @@ public static BindableProperty Create(string propertyName, Type returnType, [Dyn } /// - public static BindableProperty CreateAttached(string propertyName, Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, + public static BindableProperty CreateAttached(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWay, ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) { @@ -157,7 +159,7 @@ public static BindableProperty CreateAttached(string propertyName, Type returnTy } /// - public static BindablePropertyKey CreateAttachedReadOnly(string propertyName, Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource, + public static BindablePropertyKey CreateAttachedReadOnly(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) { @@ -167,7 +169,7 @@ public static BindablePropertyKey CreateAttachedReadOnly(string propertyName, Ty } /// - public static BindablePropertyKey CreateReadOnly(string propertyName, Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource, + public static BindablePropertyKey CreateReadOnly(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode = BindingMode.OneWayToSource, ValidateValueDelegate validateValue = null, BindingPropertyChangedDelegate propertyChanged = null, BindingPropertyChangingDelegate propertyChanging = null, CoerceValueDelegate coerceValue = null, CreateDefaultValueDelegate defaultValueCreator = null) { @@ -176,7 +178,7 @@ public static BindablePropertyKey CreateReadOnly(string propertyName, Type retur isReadOnly: true, defaultValueCreator: defaultValueCreator)); } - internal static BindableProperty Create(string propertyName, Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, + internal static BindableProperty Create(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, CreateDefaultValueDelegate defaultValueCreator = null) { @@ -184,7 +186,7 @@ internal static BindableProperty Create(string propertyName, Type returnType, [D defaultValueCreator: defaultValueCreator); } - internal static BindableProperty CreateAttached(string propertyName, Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, + internal static BindableProperty CreateAttached(string propertyName, [DynamicallyAccessedMembers(ReturnTypeMembers)] Type returnType, [DynamicallyAccessedMembers(DeclaringTypeMembers)] Type declaringType, object defaultValue, BindingMode defaultBindingMode, ValidateValueDelegate validateValue, BindingPropertyChangedDelegate propertyChanged, BindingPropertyChangingDelegate propertyChanging, CoerceValueDelegate coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly, CreateDefaultValueDelegate defaultValueCreator = null) { diff --git a/src/Controls/src/Core/DependencyService.cs b/src/Controls/src/Core/DependencyService.cs index eac1f1cc5156..242e5fa8c1bd 100644 --- a/src/Controls/src/Core/DependencyService.cs +++ b/src/Controls/src/Core/DependencyService.cs @@ -16,7 +16,7 @@ public static class DependencyService static readonly object s_dependencyLock = new object(); static readonly object s_initializeLock = new object(); - static readonly List DependencyTypes = new List(); + static readonly List DependencyTypes = new List(); static readonly Dictionary DependencyImplementations = new Dictionary(); public static T Resolve<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(DependencyFetchTarget fallbackFetchTarget = DependencyFetchTarget.GlobalInstance) where T : class @@ -64,16 +64,14 @@ public static class DependencyService public static void Register<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T>() where T : class { Type type = typeof(T); - if (!DependencyTypes.Contains(type)) - DependencyTypes.Add(type); + AddDependencyTypeIfNeeded(type); } public static void Register<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TImpl>() where T : class where TImpl : class, T { Type targetType = typeof(T); Type implementorType = typeof(TImpl); - if (!DependencyTypes.Contains(targetType)) - DependencyTypes.Add(targetType); + AddDependencyTypeIfNeeded(targetType); lock (s_dependencyLock) DependencyImplementations[targetType] = new DependencyData { ImplementorType = implementorType }; @@ -83,16 +81,22 @@ public static class DependencyService { Type targetType = typeof(T); Type implementorType = typeof(T); - if (!DependencyTypes.Contains(targetType)) - DependencyTypes.Add(targetType); + AddDependencyTypeIfNeeded(targetType); lock (s_dependencyLock) DependencyImplementations[targetType] = new DependencyData { ImplementorType = implementorType, GlobalInstance = instance }; } + static void AddDependencyTypeIfNeeded( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type type) + { + if (!DependencyTypes.Any(t => t.Type == type)) + DependencyTypes.Add(new DependencyType { Type = type }); + } + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] static Type FindImplementor(Type target) => - DependencyTypes.FirstOrDefault(t => target.IsAssignableFrom(t)); + DependencyTypes.FirstOrDefault(t => target.IsAssignableFrom(t.Type)).Type; // Once we get essentials/cg converted to using startup.cs // we will delete the initialize code from here and just use @@ -137,10 +141,7 @@ public static void Register(Assembly[] assemblies) for (int i = 0; i < attributes.Length; i++) { DependencyAttribute attribute = (DependencyAttribute)attributes[i]; - if (!DependencyTypes.Contains(attribute.Implementor)) - { - DependencyTypes.Add(attribute.Implementor); - } + AddDependencyTypeIfNeeded(attribute.Implementor); } } } @@ -169,5 +170,11 @@ class DependencyData [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] public Type ImplementorType { get; set; } } + + struct DependencyType + { + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + public Type Type { get; set; } + } } } diff --git a/src/Controls/src/Core/Internals/CellExtensions.cs b/src/Controls/src/Core/Internals/CellExtensions.cs index d609cd0f0ab5..760e6866c82a 100644 --- a/src/Controls/src/Core/Internals/CellExtensions.cs +++ b/src/Controls/src/Core/Internals/CellExtensions.cs @@ -9,28 +9,30 @@ namespace Microsoft.Maui.Controls.Internals [EditorBrowsable(EditorBrowsableState.Never)] public static class CellExtensions { - public static bool GetIsGroupHeader(this TItem cell) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject + const DynamicallyAccessedMemberTypes ItemTypeMembers = BindableProperty.DeclaringTypeMembers | BindableProperty.ReturnTypeMembers; + + public static bool GetIsGroupHeader(this TItem cell) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject { return TemplatedItemsList.GetIsGroupHeader(cell); } - public static void SetIsGroupHeader(this TItem cell, bool value) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject + public static void SetIsGroupHeader(this TItem cell, bool value) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject { TemplatedItemsList.SetIsGroupHeader(cell, value); } - public static TItem GetGroupHeaderContent(this TItem cell) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject + public static TItem GetGroupHeaderContent(this TItem cell) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject { var group = TemplatedItemsList.GetGroup(cell); return group.HeaderContent; } - public static int GetIndex(this TItem cell) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject + public static int GetIndex(this TItem cell) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject { return TemplatedItemsList.GetIndex(cell); } - public static ITemplatedItemsList GetGroup(this TItem cell) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject + public static ITemplatedItemsList GetGroup(this TItem cell) where TView : BindableObject, ITemplatedItemsView where TItem : BindableObject { return TemplatedItemsList.GetGroup(cell); } diff --git a/src/Controls/src/Core/ItemsView.cs b/src/Controls/src/Core/ItemsView.cs index 87016151347f..6da264ece396 100644 --- a/src/Controls/src/Core/ItemsView.cs +++ b/src/Controls/src/Core/ItemsView.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Controls { /// - public abstract class ItemsView<[DynamicallyAccessedMembers(BindableProperty.DeclaringTypeMembers)] TVisual> : View, ITemplatedItemsView where TVisual : BindableObject + public abstract class ItemsView<[DynamicallyAccessedMembers(BindableProperty.DeclaringTypeMembers | BindableProperty.ReturnTypeMembers)] TVisual> : View, ITemplatedItemsView where TVisual : BindableObject { /* /// Bindable property for . diff --git a/src/Controls/src/Core/ResourceDictionary.cs b/src/Controls/src/Core/ResourceDictionary.cs index 590e66e34a9d..be4ff7684758 100644 --- a/src/Controls/src/Core/ResourceDictionary.cs +++ b/src/Controls/src/Core/ResourceDictionary.cs @@ -47,7 +47,7 @@ public void SetAndLoadSource(Uri value, string resourcePath, Assembly assembly, //this will return a type if the RD as an x:Class element, and codebehind var type = XamlResourceIdAttribute.GetTypeForPath(assembly, resourcePath); if (type != null) - _mergedInstance = s_instances.GetValue(type, (key) => (ResourceDictionary)Activator.CreateInstance(key)); + _mergedInstance = s_instances.GetValue(type, _ => (ResourceDictionary)Activator.CreateInstance(type)); else _mergedInstance = DependencyService.Get().CreateFromResource(resourcePath, assembly, lineInfo); OnValuesChanged(_mergedInstance.ToArray()); diff --git a/src/Controls/src/Core/Routing.cs b/src/Controls/src/Core/Routing.cs index a1c01857aae0..675a9b6d5595 100644 --- a/src/Controls/src/Core/Routing.cs +++ b/src/Controls/src/Core/Routing.cs @@ -119,8 +119,15 @@ internal static void Clear() } /// Bindable property for attached property Route. - public static readonly BindableProperty RouteProperty = - BindableProperty.CreateAttached("Route", typeof(string), typeof(Routing), null, + public static readonly BindableProperty RouteProperty = CreateRouteProperty(); + + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111:ReflectionToDynamicallyAccessedMembers", + Justification = "The CreateAttached method has a DynamicallyAccessedMembers annotation for all public methods" + + "on the declaring type. This includes the Routing.RegisterRoute(string, Type) method which also has a " + + "DynamicallyAccessedMembers annotation and the trimmer can't guarantee the availability of the requirements" + + "of the method. `BindableProperty` only needs methods starting with `Get`, so `RegisterRoute` is never accessed via reflection.")] + private static BindableProperty CreateRouteProperty() + => BindableProperty.CreateAttached("Route", typeof(string), typeof(Routing), null, defaultValueCreator: CreateDefaultRoute); static object CreateDefaultRoute(BindableObject bindable) diff --git a/src/Controls/src/Core/TemplatedItemsList.cs b/src/Controls/src/Core/TemplatedItemsList.cs index bb5544bcec09..18b2b0a4e99f 100644 --- a/src/Controls/src/Core/TemplatedItemsList.cs +++ b/src/Controls/src/Core/TemplatedItemsList.cs @@ -15,7 +15,7 @@ namespace Microsoft.Maui.Controls.Internals { [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class TemplatedItemsList : BindableObject, ITemplatedItemsList, IList, IDisposable + public sealed class TemplatedItemsList : BindableObject, ITemplatedItemsList, IList, IDisposable where TView : BindableObject, IItemsView where TItem : BindableObject { diff --git a/src/Controls/src/Core/Xaml/TypeConversionExtensions.cs b/src/Controls/src/Core/Xaml/TypeConversionExtensions.cs index aac944df0a3b..0fa3b2f7568b 100644 --- a/src/Controls/src/Core/Xaml/TypeConversionExtensions.cs +++ b/src/Controls/src/Core/Xaml/TypeConversionExtensions.cs @@ -50,7 +50,7 @@ internal static object ConvertTo(this object value, Type toType, Func()?.GetConverterType(); if (convertertype == null) return null; return (TypeConverter)Activator.CreateInstance(convertertype); @@ -69,7 +69,7 @@ internal static object ConvertTo(this object value, Type toType, Func()?.GetConverterType() is Type converterType) { converter = (TypeConverter)Activator.CreateInstance(converterType); } @@ -86,7 +86,7 @@ internal static object ConvertTo(this object value, Type toType, Func()?.GetConverterType() is Type converterType) { converter = (TypeConverter)Activator.CreateInstance(converterType); } @@ -101,20 +101,9 @@ internal static object ConvertTo(this object value, Type toType, Func attributes) - { - foreach (var converterAttribute in attributes) - { - if (converterAttribute.AttributeType != typeof(System.ComponentModel.TypeConverterAttribute)) - continue; - var ctor = converterAttribute.ConstructorArguments[0]; - if (ctor.ArgumentType == typeof(string)) - return Type.GetType((string)ctor.Value); - if (ctor.ArgumentType == typeof(Type)) - return (Type)ctor.Value; - } - return null; - } + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + static Type GetConverterType(this TypeConverterAttribute attribute) + => Type.GetType(attribute.ConverterTypeName); //Don't change the name or the signature of this, it's used by XamlC public static object ConvertTo( diff --git a/src/Core/src/HotReload/HotReloadHelper.cs b/src/Core/src/HotReload/HotReloadHelper.cs index 41d2f622aa1a..450ac355fd7a 100644 --- a/src/Core/src/HotReload/HotReloadHelper.cs +++ b/src/Core/src/HotReload/HotReloadHelper.cs @@ -24,22 +24,29 @@ public static void Reset() } public static bool IsEnabled { get; set; } = Debugger.IsAttached; + internal static bool IsSupported +#if !NETSTANDARD + => System.Reflection.Metadata.MetadataUpdater.IsSupported; +#else + => true; +#endif + public static void Register(IHotReloadableView view, params object[] parameters) { - if (!IsEnabled) + if (!IsSupported || !IsEnabled) return; currentViews[view] = parameters; } public static void UnRegister(IHotReloadableView view) { - if (!IsEnabled) + if (!IsSupported || !IsEnabled) return; currentViews.Remove(view); } public static bool IsReplacedView(IHotReloadableView view, IView newView) { - if (!IsEnabled) + if (!IsSupported || !IsEnabled) return false; if (view == null || newView == null) return false; @@ -50,7 +57,7 @@ public static bool IsReplacedView(IHotReloadableView view, IView newView) } public static IView GetReplacedView(IHotReloadableView view) { - if (!IsEnabled) + if (!IsSupported || !IsEnabled) return view; var viewType = view.GetType(); @@ -83,7 +90,6 @@ public static IView GetReplacedView(IHotReloadableView view) static void TransferState(IHotReloadableView oldView, IView newView) { - oldView.TransferState(newView); } @@ -93,7 +99,7 @@ static void TransferState(IHotReloadableView oldView, IView newView) static Dictionary>> replacedHandlers = new(StringComparer.Ordinal); public static void RegisterReplacedView(string oldViewType, Type newViewType) { - if (!IsEnabled) + if (!IsSupported || !IsEnabled) return; Action executeStaticMethod = (method) => diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs index 436b8963793c..496b7dae5f2d 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs @@ -139,21 +139,6 @@ public static void AssertWarnings(this List actualWarnings, Lis } }, new WarningsPerFile - { - File = "src/Controls/src/Core/ResourceDictionary.cs", - WarningsPerCode = new List - { - new WarningsPerCode - { - Code = "IL2067", - Messages = new List - { - "Microsoft.Maui.Controls.ResourceDictionary.<>c.b__8_0(Type): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter 'key' of method 'Microsoft.Maui.Controls.ResourceDictionary.<>c.b__8_0(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", - } - }, - } - }, - new WarningsPerFile { File = "src/Controls/src/Xaml/XamlParser.cs", WarningsPerCode = new List @@ -185,37 +170,6 @@ public static void AssertWarnings(this List actualWarnings, Lis } }, new WarningsPerFile - { - File = "src/Controls/src/Core/BindableProperty.cs", - WarningsPerCode = new List - { - new WarningsPerCode - { - Code = "IL2067", - Messages = new List - { - "Microsoft.Maui.Controls.BindableProperty.BindableProperty(String,Type,Type,Object,BindingMode,BindableProperty.ValidateValueDelegate,BindableProperty.BindingPropertyChangedDelegate,BindableProperty.BindingPropertyChangingDelegate,BindableProperty.CoerceValueDelegate,BindableProperty.BindablePropertyBindingChanging,Boolean,BindableProperty.CreateDefaultValueDelegate): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter '#1' of method 'Microsoft.Maui.Controls.BindableProperty.BindableProperty(String,Type,Type,Object,BindingMode,BindableProperty.ValidateValueDelegate,BindableProperty.BindingPropertyChangedDelegate,BindableProperty.BindingPropertyChangingDelegate,BindableProperty.CoerceValueDelegate,BindableProperty.BindablePropertyBindingChanging,Boolean,BindableProperty.CreateDefaultValueDelegate)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", - } - }, - } - }, - new WarningsPerFile - { - File = "src/Core/src/HotReload/HotReloadHelper.cs", - WarningsPerCode = new List - { - new WarningsPerCode - { - Code = "IL2067", - Messages = new List - { - "Microsoft.Maui.HotReload.MauiHotReloadHelper.GetReplacedView(IHotReloadableView): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter '#ILLink.Shared.TypeSystemProxy.ParameterIndex' of method 'System.Collections.Generic.Dictionary`2.TryGetValue(String,Type&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", - "Microsoft.Maui.HotReload.MauiHotReloadHelper.GetReplacedView(IHotReloadableView): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Activator.CreateInstance(Type,Object[])'. The parameter '#ILLink.Shared.TypeSystemProxy.ParameterIndex' of method 'System.Collections.Generic.Dictionary`2.TryGetValue(String,Type&)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", - } - }, - } - }, - new WarningsPerFile { File = "src/Controls/src/Core/Xaml/TypeConversionExtensions.cs", WarningsPerCode = new List @@ -229,39 +183,6 @@ public static void AssertWarnings(this List actualWarnings, Lis "Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetImplicitConversionOperator(Type,Type,Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethods(BindingFlags)'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetImplicitConversionOperator(Type,Type,Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", } }, - new WarningsPerCode - { - Code = "IL2072", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.<>c__DisplayClass2_0.b__0(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetTypeConverterType(IEnumerable`1)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", - "Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.<>c__DisplayClass2_0.b__0(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetTypeConverterType(IEnumerable`1)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", - "Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.<>c__DisplayClass1_0.b__0(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetTypeConverterType(IEnumerable`1)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", - } - }, - new WarningsPerCode - { - Code = "IL2057", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.TypeConversionExtensions.GetTypeConverterType(IEnumerable`1): Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.", - } - }, - } - }, - new WarningsPerFile - { - File = "src/Controls/src/Core/Routing.cs", - WarningsPerCode = new List - { - new WarningsPerCode - { - Code = "IL2111", - Messages = new List - { - "Microsoft.Maui.Controls.Routing..cctor(): Method 'Microsoft.Maui.Controls.Routing.RegisterRoute(String,Type)' with parameters or return value with `DynamicallyAccessedMembersAttribute` is accessed via reflection. Trimmer can't guarantee availability of the requirements of the method.", - } - }, } }, new WarningsPerFile @@ -281,21 +202,6 @@ public static void AssertWarnings(this List actualWarnings, Lis } }, new WarningsPerFile - { - File = "src/Controls/src/Core/DependencyService.cs", - WarningsPerCode = new List - { - new WarningsPerCode - { - Code = "IL2073", - Messages = new List - { - "Microsoft.Maui.Controls.DependencyService.FindImplementor(Type): 'Microsoft.Maui.Controls.DependencyService.FindImplementor(Type)' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' requirements. The return value of method 'System.Linq.Enumerable.FirstOrDefault(IEnumerable`1,Func`2)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.", - } - }, - } - }, - new WarningsPerFile { File = "src/Controls/src/Core/BindablePropertyConverter.cs", WarningsPerCode = new List