diff --git a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs index bfaf6ff96fab29..2a9e861a49d2ca 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs @@ -16,7 +16,7 @@ namespace System public abstract partial class Array : ICloneable, IList, IStructuralComparable, IStructuralEquatable { // Create instance will create an array - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static unsafe Array CreateInstance(Type elementType, int length) { if (elementType is null) @@ -69,7 +69,7 @@ public static unsafe Array CreateInstance(Type elementType, int length1, int len return InternalCreate((void*)t.TypeHandle.Value, 3, pLengths, null); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static unsafe Array CreateInstance(Type elementType, params int[] lengths) { if (elementType is null) @@ -95,7 +95,7 @@ public static unsafe Array CreateInstance(Type elementType, params int[] lengths return InternalCreate((void*)t.TypeHandle.Value, lengths.Length, pLengths, null); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static unsafe Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds) { if (elementType == null) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs index 9bfdf7c64b36d6..13686657722e42 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs @@ -323,11 +323,13 @@ public override Type MakeByRefType() return SymbolType.FormCompoundType("&", this, 0)!; } + [RequiresDynamicCodeAttribute("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return SymbolType.FormCompoundType("[]", this, 0)!; } + [RequiresDynamicCodeAttribute("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { string s = GetRankString(rank); diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs index c96319b52cc5f9..bf3fecf702f060 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs @@ -68,11 +68,13 @@ public override Type MakeByRefType() return SymbolType.FormCompoundType("&", this, 0)!; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return SymbolType.FormCompoundType("[]", this, 0)!; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { string s = GetRankString(rank); @@ -195,6 +197,7 @@ public override Type MakeArrayType(int rank) public override Type GetGenericTypeDefinition() { throw new InvalidOperationException(); } + [RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")] [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] public override Type MakeGenericType(params Type[] typeArguments) { throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericTypeDefinition, this)); } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs index 87bc1b9156fc81..3ede51661363b2 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs @@ -1081,11 +1081,13 @@ public override Type MakeByRefType() return SymbolType.FormCompoundType("&", this, 0)!; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return SymbolType.FormCompoundType("[]", this, 0)!; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { string s = GetRankString(rank); @@ -1165,6 +1167,7 @@ public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] nam return m_inst; } + [RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")] [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] public override Type MakeGenericType(params Type[] typeArguments) { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs index 0059de15e5d9de..6c9807beccdef4 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime; using System.Runtime.CompilerServices; @@ -502,6 +503,8 @@ public static object ConvertNativeComInterfaceToManaged(IntPtr pUnk) #endif } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "This API will be called from compiler generated code only.")] internal static int AsAnyGetNativeSize(object o) { // Array, string and StringBuilder are not implemented. @@ -516,6 +519,8 @@ o is string || return Marshal.SizeOf(o.GetType()); } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "This API will be called from compiler generated code only.")] internal static void AsAnyMarshalManagedToNative(object o, IntPtr address) { // Array, string and StringBuilder are not implemented. @@ -542,6 +547,8 @@ o is string || Marshal.PtrToStructureImpl(address, o); } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "This API will be called from compiler generated code only.")] internal static void AsAnyCleanupNative(IntPtr address, object o) { // Array, string and StringBuilder are not implemented. diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.CoreRT.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.CoreRT.cs index 9fee9c1bb39d8a..8957c3721385d0 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.CoreRT.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Array.CoreRT.cs @@ -63,7 +63,7 @@ internal bool IsSzArray return EETypePtr.EETypePtrOf().ToPointer(); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static Array CreateInstance(Type elementType, int length) { if (elementType is null) @@ -111,7 +111,7 @@ public static unsafe Array CreateInstance(Type elementType, int length1, int len return NewMultiDimArray(arrayType.TypeHandle.ToEETypePtr(), pLengths, 3); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static Array CreateInstance(Type elementType, params int[] lengths) { if (elementType is null) @@ -140,7 +140,7 @@ public static Array CreateInstance(Type elementType, params int[] lengths) } } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds) { if (elementType is null) @@ -157,7 +157,7 @@ public static Array CreateInstance(Type elementType, int[] lengths, int[] lowerB return CreateMultiDimArray(elementType, lengths, lowerBounds); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] private static Array CreateSzArray(Type elementType, int length) { // Though our callers already validated length once, this parameter is passed via arrays, so we must check it again @@ -169,7 +169,7 @@ private static Array CreateSzArray(Type elementType, int length) return RuntimeImports.RhNewArray(arrayType.TypeHandle.ToEETypePtr(), length); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] private static Array CreateMultiDimArray(Type elementType, int[] lengths, int[] lowerBounds) { Debug.Assert(lengths != null); @@ -186,7 +186,7 @@ private static Array CreateMultiDimArray(Type elementType, int[] lengths, int[] return RuntimeAugments.NewMultiDimArray(arrayType.TypeHandle, lengths, lowerBounds); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] private static Type GetArrayTypeFromElementType(Type elementType, bool multiDim, int rank) { elementType = elementType.UnderlyingSystemType; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs index 1ebf2df1735877..006f893e0e9c1c 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs @@ -357,11 +357,13 @@ protected override bool IsValueTypeImpl() return default; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return default; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { return default; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs index 5adce89c2ab317..ea0284c4d0dfb8 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs @@ -413,11 +413,13 @@ protected override bool IsValueTypeImpl() return default; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return default; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { return default; @@ -428,6 +430,7 @@ public override Type MakeByRefType() return default; } + [RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")] [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] public override Type MakeGenericType(params Type[] typeArguments) { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs index b95a4ce8e69ccf..c156687c4b6bb9 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs @@ -622,11 +622,13 @@ public override bool IsVariableBoundArray } } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return default; } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { return default; @@ -637,6 +639,7 @@ public override Type MakeByRefType() return default; } + [RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")] [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] public override Type MakeGenericType(params Type[] typeArguments) { diff --git a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/RuntimeTypeInfo.cs b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/RuntimeTypeInfo.cs index d4605c1a900131..6d1fd826f65188 100644 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/RuntimeTypeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/RuntimeTypeInfo.cs @@ -204,7 +204,7 @@ internal static RuntimeTypeInfo GetRuntimeTypeInfo(RuntimeTypeHandle typeHandle) return RuntimeTypeTable.Table.GetOrAdd(new RuntimeTypeHandleKey(typeHandle)); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { // We support enough of MakeArrayType to make enum operations work diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs index e175f500abefec..877f39f4b2d09c 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs @@ -424,7 +424,7 @@ public override Type GetGenericTypeDefinition() throw new InvalidOperationException(SR.InvalidOperation_NotGenericType); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public sealed override Type MakeArrayType() { #if ENABLE_REFLECTION_TRACE @@ -438,7 +438,7 @@ public sealed override Type MakeArrayType() return this.GetArrayTypeWithTypeHandle(); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public sealed override Type MakeArrayType(int rank) { #if ENABLE_REFLECTION_TRACE diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/Variant.cs b/src/libraries/Common/src/System/Runtime/InteropServices/Variant.cs index 60e880a4ffe8c9..2af1f942acee68 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/Variant.cs +++ b/src/libraries/Common/src/System/Runtime/InteropServices/Variant.cs @@ -20,7 +20,7 @@ static Variant() { // Variant size is the size of 4 pointers (16 bytes) on a 32-bit processor, // and 3 pointers (24 bytes) on a 64-bit processor. - int variantSize = Marshal.SizeOf(typeof(Variant)); + int variantSize = Marshal.SizeOf(); if (IntPtr.Size == 4) { Debug.Assert(variantSize == (4 * IntPtr.Size)); diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs index 431cddcca4f682..869434e546471b 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs @@ -14,6 +14,7 @@ namespace Internal.Runtime.InteropServices public static class ComponentActivator { private const string TrimIncompatibleWarningMessage = "Native hosting is not trim compatible and this warning will be seen if trimming is enabled."; + private const string NativeAOTIncompatibleWarningMessage = "The native code for the method requested might not be available at runtime."; [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] @@ -49,6 +50,7 @@ private static string MarshalToString(IntPtr arg, string argName) /// Assembly qualified delegate type name /// Extensibility parameter (currently unused) /// Pointer where to store the function pointer result + [RequiresDynamicCode(NativeAOTIncompatibleWarningMessage)] [RequiresUnreferencedCode(TrimIncompatibleWarningMessage, Url = "https://aka.ms/dotnet-illink/nativehost")] [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] @@ -103,6 +105,7 @@ public static unsafe int LoadAssemblyAndGetFunctionPointer(IntPtr assemblyPathNa /// Extensibility parameter (currently unused) /// Extensibility parameter (currently unused) /// Pointer where to store the function pointer result + [RequiresDynamicCode(NativeAOTIncompatibleWarningMessage)] [UnmanagedCallersOnly] public static unsafe int GetFunctionPointer(IntPtr typeNameNative, IntPtr methodNameNative, @@ -164,6 +167,7 @@ private static IsolatedComponentLoadContext GetIsolatedComponentLoadContext(stri return alc; } + [RequiresDynamicCode(NativeAOTIncompatibleWarningMessage)] [RequiresUnreferencedCode(TrimIncompatibleWarningMessage, Url = "https://aka.ms/dotnet-illink/nativehost")] private static IntPtr InternalGetFunctionPointer(AssemblyLoadContext alc, string typeName, diff --git a/src/libraries/System.Private.CoreLib/src/System/Array.cs b/src/libraries/System.Private.CoreLib/src/System/Array.cs index 1c4c876d46a8a3..371705fc953c50 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Array.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Array.cs @@ -67,7 +67,7 @@ ref MemoryMarshal.GetArrayDataReference(larray), Debug.Assert(array != null); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static Array CreateInstance(Type elementType, params long[] lengths) { if (lengths == null) diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs index 3031c5cef109cb..3bd61b255e20b4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs @@ -696,7 +696,7 @@ public static ArrayList Synchronized(ArrayList list!!) // downcasting all elements. This copy may fail and is an O(n) operation. // Internally, this implementation calls Array.Copy. // - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public virtual Array ToArray(Type type!!) { Array array = Array.CreateInstance(type, _size); @@ -1068,7 +1068,7 @@ public override void Sort(int index, int count, IComparer? comparer) return array; } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Array ToArray(Type type!!) { Array array = Array.CreateInstance(type, _list.Count); @@ -1459,7 +1459,7 @@ public override void Sort(int index, int count, IComparer? comparer) } } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Array ToArray(Type type) { lock (_root) @@ -1842,7 +1842,7 @@ public override void Sort(int index, int count, IComparer? comparer) return _list.ToArray(); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Array ToArray(Type type) { return _list.ToArray(type); @@ -2094,7 +2094,7 @@ public override void Sort(int index, int count, IComparer? comparer) return _list.ToArray(); } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Array ToArray(Type type) { return _list.ToArray(type); @@ -2536,7 +2536,7 @@ public override object? this[int index] return array; } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Array ToArray(Type type!!) { InternalUpdateRange(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureType.cs index 8bebe753e08a11..1d7251ed5df2e8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureType.cs @@ -37,9 +37,9 @@ internal abstract class SignatureType : Type public sealed override MemberTypes MemberType => MemberTypes.TypeInfo; // Compositors - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public sealed override Type MakeArrayType() => new SignatureArrayType(this, rank: 1, isMultiDim: false); - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public sealed override Type MakeArrayType(int rank) { if (rank <= 0) diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs index d87c3d1d122b33..5ccdb9f2b6f406 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs @@ -45,6 +45,10 @@ internal ResourceReader(Stream stream, Dictionary resCa ReadResources(); } + [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = "InitializeBinaryFormatter will get trimmed out when AllowCustomResourceTypes is set to false. " + + "When set to true, we will already throw a warning for this feature switch, so we suppress this one in order for" + + "the user to only get one error.")] [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "InitializeBinaryFormatter will get trimmed out when AllowCustomResourceTypes is set to false. " + "When set to true, we will already throw a warning for this feature switch, so we suppress this one in order for" + @@ -85,6 +89,7 @@ private object DeserializeObject(int typeIndex) } // Issue https://github.com/dotnet/runtime/issues/39290 tracks finding an alternative to BinaryFormatter + [RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")] [RequiresUnreferencedCode("The CustomResourceTypesSupport feature switch has been enabled for this app which is being trimmed. " + "Custom readers as well as custom objects on the resources file are not observable by the trimmer and so required assemblies, types and members may be removed.")] private bool InitializeBinaryFormatter() diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.cs b/src/libraries/System.Private.CoreLib/src/System/Type.cs index d17c9a1fd627af..f92f977a0f1c6e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.cs @@ -504,9 +504,9 @@ public virtual Array GetEnumValues() throw NotImplemented.ByDesign; } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public virtual Type MakeArrayType() => throw new NotSupportedException(); - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public virtual Type MakeArrayType(int rank) => throw new NotSupportedException(); public virtual Type MakeByRefType() => throw new NotSupportedException(); diff --git a/src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs b/src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs index 318fc38c95d7e2..7e4679ed8de1cb 100644 --- a/src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs +++ b/src/libraries/System.Reflection.Emit/ref/System.Reflection.Emit.cs @@ -164,7 +164,9 @@ internal EnumBuilder() { } protected override bool IsPointerImpl() { throw null; } protected override bool IsPrimitiveImpl() { throw null; } protected override bool IsValueTypeImpl() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The code for an array of the specified type might not be available.")] public override System.Type MakeArrayType() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The code for an array of the specified type might not be available.")] public override System.Type MakeArrayType(int rank) { throw null; } public override System.Type MakeByRefType() { throw null; } public override System.Type MakePointerType() { throw null; } @@ -286,9 +288,12 @@ internal GenericTypeParameterBuilder() { } protected override bool IsPrimitiveImpl() { throw null; } public override bool IsSubclassOf(System.Type c) { throw null; } protected override bool IsValueTypeImpl() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The code for an array of the specified type might not be available.")] public override System.Type MakeArrayType() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The code for an array of the specified type might not be available.")] public override System.Type MakeArrayType(int rank) { throw null; } public override System.Type MakeByRefType() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The native code for this instantiation might not be available at runtime.")] [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] public override System.Type MakeGenericType(params System.Type[] typeArguments) { throw null; } public override System.Type MakePointerType() { throw null; } @@ -571,9 +576,12 @@ public void DefineMethodOverride(System.Reflection.MethodInfo methodInfoBody, Sy protected override bool IsPointerImpl() { throw null; } protected override bool IsPrimitiveImpl() { throw null; } public override bool IsSubclassOf(System.Type c) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The code for an array of the specified type might not be available.")] public override System.Type MakeArrayType() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The code for an array of the specified type might not be available.")] public override System.Type MakeArrayType(int rank) { throw null; } public override System.Type MakeByRefType() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The native code for this instantiation might not be available at runtime.")] [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] public override System.Type MakeGenericType(params System.Type[] typeArguments) { throw null; } public override System.Type MakePointerType() { throw null; } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 14b94ebd0629eb..30cf04df74d667 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -342,15 +342,15 @@ public static void Copy(System.Array sourceArray, int sourceIndex, System.Array public static void Copy(System.Array sourceArray, long sourceIndex, System.Array destinationArray, long destinationIndex, long length) { } public void CopyTo(System.Array array, int index) { } public void CopyTo(System.Array array, long index) { } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static System.Array CreateInstance(System.Type elementType, int length) { throw null; } public static System.Array CreateInstance(System.Type elementType, int length1, int length2) { throw null; } public static System.Array CreateInstance(System.Type elementType, int length1, int length2, int length3) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static System.Array CreateInstance(System.Type elementType, params int[] lengths) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static System.Array CreateInstance(System.Type elementType, int[] lengths, int[] lowerBounds) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static System.Array CreateInstance(System.Type elementType, params long[] lengths) { throw null; } public static T[] Empty() { throw null; } public static bool Exists(T[] array, System.Predicate match) { throw null; } @@ -6904,9 +6904,9 @@ protected Type() { } protected abstract bool IsPrimitiveImpl(); public virtual bool IsSubclassOf(System.Type c) { throw null; } protected virtual bool IsValueTypeImpl() { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The code for an array of the specified type might not be available.")] public virtual System.Type MakeArrayType() { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The code for an array of the specified type might not be available.")] public virtual System.Type MakeArrayType(int rank) { throw null; } public virtual System.Type MakeByRefType() { throw null; } public static System.Type MakeGenericMethodParameter(int position) { throw null; } @@ -8337,7 +8337,7 @@ public virtual void Sort(int index, int count, System.Collections.IComparer? com public static System.Collections.ArrayList Synchronized(System.Collections.ArrayList list) { throw null; } public static System.Collections.IList Synchronized(System.Collections.IList list) { throw null; } public virtual object?[] ToArray() { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The code for an array of the specified type might not be available.")] public virtual System.Array ToArray(System.Type type) { throw null; } public virtual void TrimToSize() { } } diff --git a/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs index 5e2348a2257f59..e774619f5b4985 100644 --- a/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs @@ -282,7 +282,7 @@ private static bool CanAssignArrayElement(Type source, Type target) return false; } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static unsafe Array CreateInstance(Type elementType, int length) { if (elementType is null) @@ -342,7 +342,7 @@ public static unsafe Array CreateInstance(Type elementType, int length1, int len return array; } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static unsafe Array CreateInstance(Type elementType, params int[] lengths) { if (elementType is null) @@ -367,7 +367,7 @@ public static unsafe Array CreateInstance(Type elementType, params int[] lengths return array; } - [RequiresDynamicCode("The native code for the array might not be available at runtime.")] + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public static unsafe Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds) { if (elementType == null) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs index 91dff62fa1fbc1..de05b29ef3ec9c 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs @@ -432,11 +432,13 @@ public override bool IsDefined(Type attributeType, bool inherit) return _tb.IsDefined(attributeType, inherit); } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return new ArrayType(this, 0); } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { if (rank < 1) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs index f431161b26447e..b65c2a4a15e751 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs @@ -477,11 +477,13 @@ public override int GetHashCode() return base.GetHashCode(); } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return new ArrayType(this, 0); } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { if (rank < 1) @@ -494,6 +496,7 @@ public override Type MakeByRefType() return new ByRefType(this); } + [RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")] [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] public override Type MakeGenericType(params Type[] typeArguments) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index 2d4a277d79ac10..903f551d4ecf78 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -1372,11 +1372,13 @@ public override bool IsSZArray } } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType() { return new ArrayType(this, 0); } + [RequiresDynamicCode("The code for an array of the specified type might not be available.")] public override Type MakeArrayType(int rank) { if (rank < 1) @@ -1389,6 +1391,7 @@ public override Type MakeByRefType() return new ByRefType(this); } + [RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")] [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] public override Type MakeGenericType(params Type[] typeArguments) {