From a1096cc2ade2c0a3d2ec7ecf90c37f57d95e4269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Rozs=C3=ADval?= Date: Wed, 7 Feb 2024 17:00:04 +0100 Subject: [PATCH] [Trimming] Add a feature flag to disable XAML loading at runtime (#19310) * Add feature flag * Add rudimentary docs for feature flags * Add feature flag guards and attributes with warnings * TMP: Add TODO comment to resolve issue with XamlC calling SetAndLoadSource * Move feature flags to Core * Fix typos * List affected APIs in the docs * Add summary comment for RuntimeFeature * Improve ResourceDictionary.SetAndLoadSource * Fix comment * Rename feature switch property and name * Remove comment * Revisit ResourceDictionary * Remove annotations from ResourcesLoader * Remove fixed warnings from tests * Remove unnecessary changes * Update docs/design/FeatureSwitches.md Co-authored-by: Rolf Bjarne Kvinge * Move feature switch setup code to Controls targets file * Remove ILC System.Enum.GetValues warning * Remove unnecessary Debug fallback * Suppress trimming warnings in source-generated code * Update docs/design/FeatureSwitches.md Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com> --------- Co-authored-by: Rolf Bjarne Kvinge Co-authored-by: MartyIX <203266+MartyIX@users.noreply.github.com> --- docs/design/FeatureSwitches.md | 13 ++ src/Controls/src/Build.Tasks/XamlCTask.cs | 9 ++ .../Microsoft.Maui.Controls.targets | 12 ++ src/Controls/src/Core/ResourceDictionary.cs | 20 +++- src/Controls/src/Core/TrimmerConstants.cs | 2 + .../src/SourceGen/CodeBehindGenerator.cs | 1 + src/Controls/src/Xaml/ViewExtensions.cs | 4 + src/Core/src/Core.csproj | 6 + src/Core/src/ILLink.Substitutions.xml | 8 ++ src/Core/src/RuntimeFeature.cs | 24 ++++ .../Utilities/BuildWarningsUtilities.cs | 111 ------------------ .../Sdk/Microsoft.Maui.Sdk.Before.targets | 1 - 12 files changed, 98 insertions(+), 113 deletions(-) create mode 100644 docs/design/FeatureSwitches.md create mode 100644 src/Core/src/ILLink.Substitutions.xml create mode 100644 src/Core/src/RuntimeFeature.cs diff --git a/docs/design/FeatureSwitches.md b/docs/design/FeatureSwitches.md new file mode 100644 index 000000000000..ed40bb2ebeb4 --- /dev/null +++ b/docs/design/FeatureSwitches.md @@ -0,0 +1,13 @@ +# Feature Switches + +Certain features of MAUI can be enabled or disabled using feature switches. The easiest way to control the features is by putting the corresponding MSBuild property into the app's project file. Disabling unnecessary features can help reducing the app size when combined with the [`full` trimming mode](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options). + +| MSBuild Property Name | AppContext Setting | Description | +|-|-|-| +| MauiXamlRuntimeParsingSupport | Microsoft.Maui.RuntimeFeature.IsXamlRuntimeParsingSupported | When disabled, all XAML loading at runtime will throw an exception. This will affect usage of APIs such as the `LoadFromXaml` extension method. This feature can be safely turned off when all XAML resources are compiled using XamlC (see [XAML compilation](https://learn.microsoft.com/en-us/dotnet/maui/xaml/xamlc)). This feature is enabled by default for all configurations except for NativeAOT. | + +## MauiXamlRuntimeParsingSupport + +When this feature is disabled, the following APIs are affected: +- [`LoadFromXaml` extension methods](https://learn.microsoft.com/en-us/dotnet/maui/xaml/runtime-load) will throw runtime exceptions. +- [Disabling XAML compilation](https://learn.microsoft.com/en-us/dotnet/maui/xaml/xamlc#disable-xaml-compilation) using `[XamlCompilation(XamlCompilationOptions.Skip)]` on pages and controls or whole assemblies will cause runtime exceptions. diff --git a/src/Controls/src/Build.Tasks/XamlCTask.cs b/src/Controls/src/Build.Tasks/XamlCTask.cs index a7b7ee46f745..7fe321a1227b 100644 --- a/src/Controls/src/Build.Tasks/XamlCTask.cs +++ b/src/Controls/src/Build.Tasks/XamlCTask.cs @@ -271,6 +271,15 @@ public override bool Execute(out IList thrownExceptions) LoggingHelper.LogMessage(Low, e.StackTrace); continue; } + if (initComp.HasCustomAttributes) + { + var suppressMessageAttribute = initComp.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"); + if (suppressMessageAttribute != null) + { + LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Removing UnconditionalSuppressMessageAttribute from InitializeComponent()"); + initComp.CustomAttributes.Remove(suppressMessageAttribute); + } + } if (Type != null) InitCompForType = initComp; diff --git a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets index 74382917de4b..5a95ae630a03 100644 --- a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets +++ b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets @@ -206,4 +206,16 @@ Text="The %24(TargetFrameworkVersion) for $(ProjectName) ($(TargetFrameworkVersion)) is less than the minimum required %24(TargetFrameworkVersion) for Microsoft.Maui ($(MinTargetFrameworkVersionForMaui)). You need to increase the %24(TargetFrameworkVersion) for $(ProjectName)." /> + + + false + + + + + + diff --git a/src/Controls/src/Core/ResourceDictionary.cs b/src/Controls/src/Core/ResourceDictionary.cs index be4ff7684758..8bde40f9f0e0 100644 --- a/src/Controls/src/Core/ResourceDictionary.cs +++ b/src/Controls/src/Core/ResourceDictionary.cs @@ -5,6 +5,7 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Reflection; @@ -47,9 +48,26 @@ 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, _ => (ResourceDictionary)Activator.CreateInstance(type)); + } else - _mergedInstance = DependencyService.Get().CreateFromResource(resourcePath, assembly, lineInfo); + { + if (RuntimeFeature.IsXamlRuntimeParsingSupported) + { + _mergedInstance = DependencyService.Get().CreateFromResource(resourcePath, assembly, lineInfo); + } + else + { + // This codepath is only ever hit when XamlC is explicitly disabled for a given resource dictionary. + // The developer had to add [XamlCompilation(XamlCompilationOptions.Skip)] or to their code. + // XamlC will produce a warning in this case (MAUIG0070 or XC0010). + throw new InvalidOperationException( + $"The resource '{resourcePath}' has not been compiled using XamlC and parsing XAML resources at runtime is disabled. " + + "Ensure the resource is compiled using XamlC. Alternatively, enable parsing XAML resources at runtime by setting " + + "the MauiXamlRuntimeParsingSupport MSBuild property to true."); + } + } OnValuesChanged(_mergedInstance.ToArray()); } diff --git a/src/Controls/src/Core/TrimmerConstants.cs b/src/Controls/src/Core/TrimmerConstants.cs index c35314ab26e6..6b92e392b860 100644 --- a/src/Controls/src/Core/TrimmerConstants.cs +++ b/src/Controls/src/Core/TrimmerConstants.cs @@ -6,4 +6,6 @@ class TrimmerConstants internal const string SerializerTrimmerWarning = "Data Contract Serialization and Deserialization might require types that cannot be statically analyzed. Make sure all of the required types are preserved."; internal const string NativeBindingService = "This method properly handles missing properties, and there is not a way to preserve them from this method."; + + internal const string XamlLoadingTrimmerWarning = "Loading XAML at runtime might require types that cannot be statically analyzed. Make sure all of the required types are preserved."; } \ No newline at end of file diff --git a/src/Controls/src/SourceGen/CodeBehindGenerator.cs b/src/Controls/src/SourceGen/CodeBehindGenerator.cs index 556ebc499b4e..4461a4b1ea5c 100644 --- a/src/Controls/src/SourceGen/CodeBehindGenerator.cs +++ b/src/Controls/src/SourceGen/CodeBehindGenerator.cs @@ -220,6 +220,7 @@ static void GenerateXamlCodeBehind(ProjectItem projItem, Compilation compilation //initializeComponent sb.AppendLine($"\t\t[global::System.CodeDom.Compiler.GeneratedCode(\"Microsoft.Maui.Controls.SourceGen\", \"1.0.0.0\")]"); + sb.AppendLine($"\t\t[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2026\", Justification = \"Source-generated code will be replaced by XamlC in Release builds.\")]"); // add MemberNotNull attributes if (namedFields != null) diff --git a/src/Controls/src/Xaml/ViewExtensions.cs b/src/Controls/src/Xaml/ViewExtensions.cs index d8d586c79b53..0c6333c9d15b 100644 --- a/src/Controls/src/Xaml/ViewExtensions.cs +++ b/src/Controls/src/Xaml/ViewExtensions.cs @@ -26,24 +26,28 @@ // THE SOFTWARE. using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; namespace Microsoft.Maui.Controls.Xaml { public static class Extensions { + [RequiresUnreferencedCode(TrimmerConstants.XamlLoadingTrimmerWarning)] public static TXaml LoadFromXaml(this TXaml view, Type callingType) { XamlLoader.Load(view, callingType); return view; } + [RequiresUnreferencedCode(TrimmerConstants.XamlLoadingTrimmerWarning)] public static TXaml LoadFromXaml(this TXaml view, string xaml) { XamlLoader.Load(view, xaml); return view; } + [RequiresUnreferencedCode(TrimmerConstants.XamlLoadingTrimmerWarning)] internal static TXaml LoadFromXaml(this TXaml view, string xaml, Assembly rootAssembly) { XamlLoader.Load(view, xaml, rootAssembly); diff --git a/src/Core/src/Core.csproj b/src/Core/src/Core.csproj index b0a5c29e8d03..9c5f60706896 100644 --- a/src/Core/src/Core.csproj +++ b/src/Core/src/Core.csproj @@ -58,6 +58,12 @@ + + + ILLink.Substitutions.xml + + + <_CopyItems Include="nuget\buildTransitive\**" Exclude="nuget\**\*.in.*" /> diff --git a/src/Core/src/ILLink.Substitutions.xml b/src/Core/src/ILLink.Substitutions.xml new file mode 100644 index 000000000000..29c57a6aee1e --- /dev/null +++ b/src/Core/src/ILLink.Substitutions.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/Core/src/RuntimeFeature.cs b/src/Core/src/RuntimeFeature.cs new file mode 100644 index 000000000000..a5544cfd00cc --- /dev/null +++ b/src/Core/src/RuntimeFeature.cs @@ -0,0 +1,24 @@ +using System; + +namespace Microsoft.Maui +{ + /// + /// Contains all the runtime feature switches that are used throught the MAUI codebase. + /// See + /// for examples of how to add new feature switches. + /// + /// + /// Property names must be kept in sync with ILLink.Substitutions.xml for proper value substitutions. + /// Mapping of MSBuild properties to feature switches and the default values of feature switches + /// is defined in Microsoft.Maui.Sdk.Before.targets. + /// + internal static class RuntimeFeature + { + private const bool IsXamlRuntimeParsingSupportedByDefault = true; + + internal static bool IsXamlRuntimeParsingSupported + => AppContext.TryGetSwitch("Microsoft.Maui.RuntimeFeature.IsXamlRuntimeParsingSupported", out bool isEnabled) + ? isEnabled + : IsXamlRuntimeParsingSupportedByDefault; + } +} diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs index 49874d23c242..ba38fc0e5b40 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/Utilities/BuildWarningsUtilities.cs @@ -248,102 +248,6 @@ public static void AssertWarnings(this List actualWarnings, Lis } }, new WarningsPerFile - { - File = "src/Controls/src/Xaml/ApplyPropertiesVisitor.cs", - WarningsPerCode = new List - { - new WarningsPerCode - { - Code = "IL2072", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.Visit(ElementNode,INode): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)'. The return value of method 'System.Collections.Generic.Dictionary`2.Item.get' 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.ApplyPropertiesVisitor.Visit(ElementNode,INode): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)'. The return value of method 'System.Collections.Generic.Dictionary`2.Item.get' 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.ApplyPropertiesVisitor.Visit(ElementNode,INode): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)'. The return value of method 'System.Object.GetType()' 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.ApplyPropertiesVisitor.GetTargetProperty(Object,XmlName,Object,IXmlLineInfo): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(Type)'. The return value of method 'System.Object.GetType()' 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.ApplyPropertiesVisitor.TryConnectEvent(Object,String,Boolean,Object,Object,IXmlLineInfo,Exception&): 'name' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicEvents' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeEvent(Type,String)'. The return value of method 'System.Object.GetType()' 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.ApplyPropertiesVisitor.TryConnectEvent(Object,String,Boolean,Object,Object,IXmlLineInfo,Exception&): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicEvents', 'DynamicallyAccessedMemberTypes.NonPublicEvents' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeEvents(Type)'. The return value of method 'System.Object.GetType()' 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.ApplyPropertiesVisitor.<>c__DisplayClass37_0.b__1(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(Type)'. The return value of method 'Microsoft.Maui.Controls.BindableProperty.DeclaringType.get' 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.ApplyPropertiesVisitor.TrySetProperty(Object,String,Object,IXmlLineInfo,IServiceProvider,Object,Exception&): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(Type)'. The return value of method 'System.Object.GetType()' 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.ApplyPropertiesVisitor.TryAddToProperty(Object,XmlName,Object,String,IXmlLineInfo,IServiceProvider,Object,Exception&): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)'. The return value of method 'System.Object.GetType()' 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 = "IL2070", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.GetBindableProperty(Type,String,IXmlLineInfo,Boolean): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.GetBindableProperty(Type,String,IXmlLineInfo,Boolean)' 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.ApplyPropertiesVisitor.GetAllRuntimeMethods(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.GetAllRuntimeMethods(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 = "IL2075", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.TryGetProperty(Object,String,Object&,IXmlLineInfo,Object,Exception&,Object&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String,BindingFlags)'. The return value of method 'System.Object.GetType()' 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.ApplyPropertiesVisitor.TryConnectEvent(Object,String,Boolean,Object,Object,IXmlLineInfo,Exception&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetMethod(String,BindingFlags)'. The return value of method 'System.Object.GetType()' 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.ApplyPropertiesVisitor.TryConnectEvent(Object,String,Boolean,Object,Object,IXmlLineInfo,Exception&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. The return value of method 'System.Reflection.EventInfo.EventHandlerType.get' 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.ApplyPropertiesVisitor.TryConnectEvent(Object,String,Boolean,Object,Object,IXmlLineInfo,Exception&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetMethods(BindingFlags)'. The return value of method 'System.Object.GetType()' 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.ApplyPropertiesVisitor.TryConnectEvent(Object,String,Boolean,Object,Object,IXmlLineInfo,Exception&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. The return value of method 'System.Reflection.EventInfo.EventHandlerType.get' 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 = "IL2067", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.GetAllRuntimeMethods(Type): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.GetAllRuntimeMethods(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.Controls.Xaml.ApplyPropertiesVisitor.<>c.b__46_0(Type): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)'. The parameter 't' of method 'Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.<>c.b__46_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/CreateValuesVisitor.cs", - WarningsPerCode = new List - { - new WarningsPerCode - { - Code = "IL2075", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode,INode): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Reflection.TypeInfo.DeclaredConstructors.get'. The return value of method 'Microsoft.Maui.Controls.Xaml.XamlParser.GetElementType(XmlType,IXmlLineInfo,Assembly,XamlParseException&)' 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.CreateValuesVisitor.Visit(ElementNode,INode): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Reflection.TypeInfo.DeclaredConstructors.get'. The return value of method 'Microsoft.Maui.Controls.Xaml.XamlParser.GetElementType(XmlType,IXmlLineInfo,Assembly,XamlParseException&)' 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.CreateValuesVisitor.Visit(ElementNode,INode): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'Microsoft.Maui.Controls.Xaml.XamlParser.GetElementType(XmlType,IXmlLineInfo,Assembly,XamlParseException&)' 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 = "IL2067", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.CreateLanguagePrimitive(Type,IElementNode): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.CreateLanguagePrimitive(Type,IElementNode)' 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.CreateValuesVisitor.CreateFromFactory(Type,IElementNode): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'System.Activator.CreateInstance(Type,Object[])'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.CreateFromFactory(Type,IElementNode)' 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.CreateValuesVisitor.CreateFromFactory(Type,IElementNode): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethods(Type)'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.CreateFromFactory(Type,IElementNode)' 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 = "IL2070", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.ValidateCtorArguments(Type,IElementNode,String&): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Reflection.TypeInfo.DeclaredConstructors.get'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.ValidateCtorArguments(Type,IElementNode,String&)' 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.CreateValuesVisitor.CreateFromParameterizedConstructor(Type,IElementNode): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in call to 'System.Reflection.TypeInfo.DeclaredConstructors.get'. The parameter '#0' of method 'Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.CreateFromParameterizedConstructor(Type,IElementNode)' 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/Hosting/Internal/MauiFactory.cs", WarningsPerCode = new List @@ -439,21 +343,6 @@ public static void AssertWarnings(this List actualWarnings, Lis }, } }, - new WarningsPerFile - { - File = "src/Controls/src/Xaml/MarkupExpressionParser.cs", - WarningsPerCode = new List - { - new WarningsPerCode - { - Code = "IL2072", - Messages = new List - { - "Microsoft.Maui.Controls.Xaml.MarkupExpressionParser.ParseExpression(String&,IServiceProvider): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in call to 'System.Activator.CreateInstance(Type)'. The return value of method 'System.Object.GetType()' 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.", - } - }, - } - }, }; #region Utility methods for generating the list of expected warnings diff --git a/src/Workload/Microsoft.Maui.Sdk/Sdk/Microsoft.Maui.Sdk.Before.targets b/src/Workload/Microsoft.Maui.Sdk/Sdk/Microsoft.Maui.Sdk.Before.targets index f82e928dc619..8c0fca695cdf 100644 --- a/src/Workload/Microsoft.Maui.Sdk/Sdk/Microsoft.Maui.Sdk.Before.targets +++ b/src/Workload/Microsoft.Maui.Sdk/Sdk/Microsoft.Maui.Sdk.Before.targets @@ -20,5 +20,4 @@ win10-$(_SingleProjectHostArchitecture) <_MauiUsingDefaultRuntimeIdentifier>true -