diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index 74c2b457b9ad8..ae077a3960007 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -108,7 +108,6 @@ The .NET Foundation licenses this file to you under the MIT license. - diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MetadataOnlyType.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MetadataOnlyType.cs index cc75ded1b1185..f8a56721f8e3d 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MetadataOnlyType.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MetadataOnlyType.cs @@ -72,6 +72,9 @@ public override Array GetEnumValuesAsUnderlyingType() throw new ArgumentException(SR.Arg_MustBeEnum, "enumType"); } + public override int GetHashCode() + => RuntimeHelpers.GetHashCode(this); + public override RuntimeTypeHandle TypeHandle => GetRuntimeTypeInfo().TypeHandle; @@ -183,6 +186,11 @@ public override Type GetFunctionPointerReturnType() // Implementation shared with MetadataType // + public override string ToString() + => GetRuntimeTypeInfo().ToString(); + + public override bool Equals(object? obj) => ReferenceEquals(obj, this); + object ICloneable.Clone() => this; public override bool IsSecurityCritical => true; @@ -289,6 +297,8 @@ public override IEnumerable CustomAttributes public override IList GetCustomAttributesData() => GetRuntimeTypeInfo().GetCustomAttributesData(); + public override string Name => GetRuntimeTypeInfo().Name; + public override string? Namespace => GetRuntimeTypeInfo().Namespace; public override string? AssemblyQualifiedName => GetRuntimeTypeInfo().AssemblyQualifiedName; @@ -301,8 +311,6 @@ public override IList GetCustomAttributesData() public override Guid GUID => GetRuntimeTypeInfo().GUID; - public override string Name => GetRuntimeTypeInfo().Name; - public override bool HasSameMetadataDefinitionAs(MemberInfo other) => GetRuntimeTypeInfo().HasSameMetadataDefinitionAs(other); public override Type MakePointerType() diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.cs index 823768ad9939f..35c8e3bbe447f 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.cs @@ -31,8 +31,17 @@ internal RuntimeType(MethodTable* pUnderlyingEEType) internal RuntimeTypeInfo GetRuntimeTypeInfo() => _runtimeTypeInfo ?? CreateRuntimeTypeInfo(); + private static bool IsReflectionDisabled => false; + + private static bool DoNotThrowForNames => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForNames", out bool doNotThrow) && doNotThrow; + private static bool DoNotThrowForAssembly => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForAssembly", out bool doNotThrow) && doNotThrow; + private static bool DoNotThrowForAttributes => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForAttributes", out bool doNotThrow) && doNotThrow; + private RuntimeTypeInfo CreateRuntimeTypeInfo() { + if (IsReflectionDisabled) + throw new NotSupportedException(SR.Reflection_Disabled); + EETypePtr eeType = ToEETypePtr(); RuntimeTypeHandle runtimeTypeHandle = new RuntimeTypeHandle(eeType); @@ -186,6 +195,9 @@ public override Array GetEnumValuesAsUnderlyingType() return Enum.GetValuesAsUnderlyingType(this); } + public override int GetHashCode() + => ((nuint)_pUnderlyingEEType).GetHashCode(); + public override RuntimeTypeHandle TypeHandle => new RuntimeTypeHandle(_pUnderlyingEEType); @@ -267,7 +279,7 @@ public override Type[] GetInterfaces() } public override bool IsTypeDefinition - => (_pUnderlyingEEType->IsCanonical && !_pUnderlyingEEType->IsGeneric) || _pUnderlyingEEType->IsGenericTypeDefinition; + => (_pUnderlyingEEType->IsCanonical && !_pUnderlyingEEType->IsGeneric) || _pUnderlyingEEType->IsGenericTypeDefinition; public override bool IsGenericType => _pUnderlyingEEType->IsGeneric || _pUnderlyingEEType->IsGenericTypeDefinition; @@ -375,6 +387,16 @@ public override Type GetFunctionPointerReturnType() // Implementation shared with MetadataType // + public override string ToString() + { + if (IsReflectionDisabled) + return "0x" + ((nuint)_pUnderlyingEEType).ToString("x"); + + return GetRuntimeTypeInfo().ToString(); + } + + public override bool Equals(object? obj) => ReferenceEquals(obj, this); + object ICloneable.Clone() => this; public override bool IsSecurityCritical => true; @@ -470,31 +492,81 @@ public override bool IsDefined(Type attributeType, bool inherit) => GetRuntimeTypeInfo().IsDefined(attributeType, inherit); public override object[] GetCustomAttributes(bool inherit) - => GetRuntimeTypeInfo().GetCustomAttributes(inherit); + { + if (IsReflectionDisabled && DoNotThrowForAttributes) + return Array.Empty(); + + return GetRuntimeTypeInfo().GetCustomAttributes(inherit); + } public override object[] GetCustomAttributes(Type attributeType, bool inherit) - => GetRuntimeTypeInfo().GetCustomAttributes(attributeType, inherit); + { + if (IsReflectionDisabled && DoNotThrowForAttributes) + return Array.Empty(); + + return GetRuntimeTypeInfo().GetCustomAttributes(attributeType, inherit); + } public override IEnumerable CustomAttributes - => GetRuntimeTypeInfo().CustomAttributes; + { + get + { + if (IsReflectionDisabled && DoNotThrowForAttributes) + return Array.Empty(); + + return GetRuntimeTypeInfo().CustomAttributes; + } + } public override IList GetCustomAttributesData() - => GetRuntimeTypeInfo().GetCustomAttributesData(); + { + if (IsReflectionDisabled && DoNotThrowForAttributes) + return Array.Empty(); - public override string? Namespace => GetRuntimeTypeInfo().Namespace; + return GetRuntimeTypeInfo().GetCustomAttributesData(); + } + + public override string Name + { + get + { + if (IsReflectionDisabled && DoNotThrowForNames) + return ToString(); + + return GetRuntimeTypeInfo().Name; + } + } + + public override string? Namespace + { + get + { + if (IsReflectionDisabled && DoNotThrowForNames) + return null; + + return GetRuntimeTypeInfo().Namespace; + } + } public override string? AssemblyQualifiedName => GetRuntimeTypeInfo().AssemblyQualifiedName; public override string? FullName => GetRuntimeTypeInfo().FullName; - public override Assembly Assembly => GetRuntimeTypeInfo().Assembly; + public override Assembly Assembly + { + get + { + if (IsReflectionDisabled && DoNotThrowForAssembly) + return null!; // TODO!!!!!!!!!! + + return GetRuntimeTypeInfo().Assembly; + } + } public override Module Module => GetRuntimeTypeInfo().Module; public override Guid GUID => GetRuntimeTypeInfo().GUID; - public override string Name => GetRuntimeTypeInfo().Name; - public override bool HasSameMetadataDefinitionAs(MemberInfo other) => GetRuntimeTypeInfo().HasSameMetadataDefinitionAs(other); public override Type MakePointerType() diff --git a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionCoreCallbacksImplementation.cs b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionCoreCallbacksImplementation.cs deleted file mode 100644 index 1f806c45f344d..0000000000000 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionCoreCallbacksImplementation.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Reflection; -using Internal.Reflection.Augments; -using Internal.Runtime.Augments; - -namespace Internal.Reflection -{ - internal class ReflectionCoreCallbacksImplementation : ReflectionCoreCallbacks - { - public override EnumInfo GetEnumInfo(Type type, Func create) => - create( - RuntimeAugments.GetEnumUnderlyingType(type.TypeHandle), - Array.Empty(), - Array.Empty(), - false); - - public override DynamicInvokeInfo GetDelegateDynamicInvokeInfo(Type type) - => throw new NotSupportedException(SR.Reflection_Disabled); - public override object ActivatorCreateInstance( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - Type type, bool nonPublic) => throw new NotSupportedException(SR.Reflection_Disabled); - public override object ActivatorCreateInstance( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes) => throw new NotSupportedException(SR.Reflection_Disabled); - public override Delegate CreateDelegate(Type type, object firstArgument, MethodInfo method, bool throwOnBindFailure) => throw new NotSupportedException(SR.Reflection_Disabled); - public override Delegate CreateDelegate(Type type, MethodInfo method, bool throwOnBindFailure) => throw new NotSupportedException(SR.Reflection_Disabled); - [RequiresUnreferencedCode("The target method might be removed")] - public override Delegate CreateDelegate(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure) => throw new NotSupportedException(SR.Reflection_Disabled); - public override Delegate CreateDelegate(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target, string method, bool ignoreCase, bool throwOnBindFailure) => throw new NotSupportedException(SR.Reflection_Disabled); - public override FieldInfo GetFieldFromHandle(RuntimeFieldHandle runtimeFieldHandle) => throw new NotSupportedException(SR.Reflection_Disabled); - public override FieldInfo GetFieldFromHandle(RuntimeFieldHandle runtimeFieldHandle, RuntimeTypeHandle declaringTypeHandle) => throw new NotSupportedException(SR.Reflection_Disabled); - public override IntPtr GetFunctionPointer(RuntimeMethodHandle runtimeMethodHandle, RuntimeTypeHandle declaringTypeHandle) => throw new NotSupportedException(SR.Reflection_Disabled); - public override EventInfo GetImplicitlyOverriddenBaseClassEvent(EventInfo e) => throw new NotSupportedException(SR.Reflection_Disabled); - public override MethodInfo GetImplicitlyOverriddenBaseClassMethod(MethodInfo m) => throw new NotSupportedException(SR.Reflection_Disabled); - public override PropertyInfo GetImplicitlyOverriddenBaseClassProperty(PropertyInfo p) => throw new NotSupportedException(SR.Reflection_Disabled); - public override Assembly[] GetLoadedAssemblies() => throw new NotSupportedException(SR.Reflection_Disabled); - public override MethodBase GetMethodFromHandle(RuntimeMethodHandle runtimeMethodHandle) => throw new NotSupportedException(SR.Reflection_Disabled); - public override MethodBase GetMethodFromHandle(RuntimeMethodHandle runtimeMethodHandle, RuntimeTypeHandle declaringTypeHandle) => throw new NotSupportedException(SR.Reflection_Disabled); - public override Assembly Load(AssemblyName refName, bool throwOnFileNotFound) => throw new NotSupportedException(SR.Reflection_Disabled); - public override Assembly Load(ReadOnlySpan rawAssembly, ReadOnlySpan pdbSymbolStore) => throw new NotSupportedException(SR.Reflection_Disabled); - public override Assembly Load(string assemblyPath) => throw new NotSupportedException(SR.Reflection_Disabled); - public override void MakeTypedReference(object target, FieldInfo[] flds, out Type type, out int offset) => throw new NotSupportedException(SR.Reflection_Disabled); - public override void RunModuleConstructor(Module module) => throw new NotSupportedException(SR.Reflection_Disabled); - } -} diff --git a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionExecutionDomainCallbacksImplementation.cs b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionExecutionDomainCallbacksImplementation.cs deleted file mode 100644 index b6b2763ac46ba..0000000000000 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionExecutionDomainCallbacksImplementation.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Reflection; - -using Internal.Runtime.Augments; - -namespace Internal.Reflection -{ - internal class ReflectionExecutionDomainCallbacksImplementation : ReflectionExecutionDomainCallbacks - { - public override Exception CreateMissingMetadataException(Type typeWithMissingMetadata) => throw new NotImplementedException(); - public override Type GetArrayTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); - public override Assembly GetAssemblyForHandle(RuntimeTypeHandle typeHandle) => new RuntimeAssemblyInfo(typeHandle); - public override Type GetByRefTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); - public override Type GetConstructedGenericTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); - public override MethodInfo GetDelegateMethod(Delegate del) => throw new NotSupportedException(SR.Reflection_Disabled); - public override Exception GetExceptionForHR(int hr) => throw new NotImplementedException(); - public override Type GetMdArrayTypeForHandle(RuntimeTypeHandle typeHandle, int rank) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); - public override MethodBase GetMethodBaseFromStartAddressIfAvailable(IntPtr methodStartAddress) => null; - public override Type GetNamedTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); - public override Type GetPointerTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); - public override Type GetFunctionPointerTypeForHandle(RuntimeTypeHandle typeHandle) => RuntimeTypeInfo.GetRuntimeTypeInfo(typeHandle); - public override RuntimeTypeHandle GetTypeHandleIfAvailable(Type type) => type.TypeHandle; - public override IntPtr TryGetStaticClassConstructionContext(RuntimeTypeHandle runtimeTypeHandle) => throw new NotSupportedException(SR.Reflection_Disabled); - } -} diff --git a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/RuntimeAssemblyInfo.cs b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/RuntimeAssemblyInfo.cs deleted file mode 100644 index 71798018026c1..0000000000000 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/RuntimeAssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Collections.Generic; -using System.Reflection; - -using Internal.Reflection.Core.NonPortable; - -namespace Internal.Reflection -{ - internal sealed class RuntimeAssemblyInfo : RuntimeAssembly - { - private readonly RuntimeTypeHandle _moduleType; - - public RuntimeAssemblyInfo(RuntimeTypeHandle moduleType) - { - _moduleType = moduleType; - } - - public override bool Equals(object? o) - { - return o is RuntimeAssemblyInfo other && other._moduleType.Equals(_moduleType); - } - - public override int GetHashCode() - { - return _moduleType.GetHashCode(); - } - - public override IEnumerable CustomAttributes => new List(); - } -} 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 deleted file mode 100644 index 154d9b15f684c..0000000000000 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/RuntimeTypeInfo.cs +++ /dev/null @@ -1,307 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Collections.Concurrent; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Reflection; - -using Internal.Runtime.Augments; -using Internal.Reflection.Augments; -using Internal.Reflection.Core.NonPortable; -using System.Collections.Generic; - -namespace Internal.Reflection -{ - internal sealed class RuntimeTypeInfo : RuntimeType - { - private readonly RuntimeTypeHandle _typeHandle; - - public RuntimeTypeInfo(RuntimeTypeHandle typeHandle) - { - _typeHandle = typeHandle; - } - - private static bool DoNotThrowForNames => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForNames", out bool doNotThrow) && doNotThrow; - - private static bool DoNotThrowForAssembly => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForAssembly", out bool doNotThrow) && doNotThrow; - - private static bool DoNotThrowForAttributes => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForAttributes", out bool doNotThrow) && doNotThrow; - - public override RuntimeTypeHandle TypeHandle => _typeHandle; - - public override bool IsGenericType => RuntimeAugments.IsGenericTypeDefinition(_typeHandle) || RuntimeAugments.IsGenericType(_typeHandle); - - public override string Name => DoNotThrowForNames ? ToString() : throw new NotSupportedException(SR.Reflection_Disabled); - - public override string Namespace => DoNotThrowForNames ? "" : throw new NotSupportedException(SR.Reflection_Disabled); - - public override string FullName => Name; - - public override string AssemblyQualifiedName => throw new NotSupportedException(SR.Reflection_Disabled); - - public override Assembly Assembly => DoNotThrowForAssembly ? Assembly.GetExecutingAssembly() : throw new NotSupportedException(SR.Reflection_Disabled); - - public override Module Module => throw new NotSupportedException(SR.Reflection_Disabled); - - public override Type UnderlyingSystemType => this; - - public override Guid GUID => throw new NotSupportedException(SR.Reflection_Disabled); - - public override Type BaseType - { - get - { - if (RuntimeAugments.TryGetBaseType(_typeHandle, out RuntimeTypeHandle baseTypeHandle) && !baseTypeHandle.Equals(default)) - { - return GetRuntimeTypeInfo(baseTypeHandle); - } - - return null; - } - } - - public override bool IsByRefLike => RuntimeAugments.IsByRefLike(_typeHandle); - - protected override bool IsValueTypeImpl() - { - return RuntimeAugments.IsValueType(_typeHandle); - } - - protected override TypeCode GetTypeCodeImpl() - { - return ReflectionAugments.GetRuntimeTypeCode(this); - } - - public override string ToString() - { - return "MT" + _typeHandle.Value.ToString(); - } - - public override int GetHashCode() - { - return _typeHandle.GetHashCode(); - } - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - public override object[] GetCustomAttributes(bool inherit) => DoNotThrowForAttributes ? Array.Empty() : throw new NotSupportedException(SR.Reflection_Disabled); - - public override object[] GetCustomAttributes(Type attributeType, bool inherit) => DoNotThrowForAttributes ? Array.Empty() : throw new NotSupportedException(SR.Reflection_Disabled); - - public override IList GetCustomAttributesData() => DoNotThrowForAttributes ? new List().AsReadOnly() : throw new NotSupportedException(SR.Reflection_Disabled); - - public override Type GetElementType() - { - if (RuntimeAugments.IsArrayType(_typeHandle) || RuntimeAugments.IsUnmanagedPointerType(_typeHandle) || RuntimeAugments.IsByRefType(_typeHandle)) - { - return GetRuntimeTypeInfo(RuntimeAugments.GetRelatedParameterTypeHandle(_typeHandle)); - } - - return null; - } - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.NonPublicEvents)] - public override EventInfo GetEvent(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.NonPublicEvents)] - public override EventInfo[] GetEvents(BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] - public override FieldInfo GetField(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] - public override FieldInfo[] GetFields(BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] - [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2063:UnrecognizedReflectionPattern", - Justification = "Linker doesn't recognize always throwing method. https://github.com/mono/linker/issues/2025")] - public override Type GetInterface(string name, bool ignoreCase) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] - public override Type[] GetInterfaces() - { - int count = RuntimeAugments.GetInterfaceCount(_typeHandle); - if (count == 0) - return Type.EmptyTypes; - - Type[] result = new Type[count]; - for (int i = 0; i < result.Length; i++) - { - result[i] = GetRuntimeTypeInfo(RuntimeAugments.GetInterface(_typeHandle, i)); - } - - return result; - } - - [DynamicallyAccessedMembers(GetAllMembers)] - public override MemberInfo[] GetMembers(BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] - public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicNestedTypes)] - public override Type GetNestedType(string name, BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicNestedTypes)] - public override Type[] GetNestedTypes(BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] - public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] - public override object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) - => throw new NotSupportedException(SR.Reflection_Disabled); - - public override bool IsDefined(Type attributeType, bool inherit) => throw new NotSupportedException(SR.Reflection_Disabled); - - protected override TypeAttributes GetAttributeFlagsImpl() => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] - protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) - => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] - protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) - => throw new NotSupportedException(SR.Reflection_Disabled); - - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] - protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) - => throw new NotSupportedException(SR.Reflection_Disabled); - - protected override bool HasElementTypeImpl() - { - return RuntimeAugments.IsArrayType(_typeHandle) || RuntimeAugments.IsUnmanagedPointerType(_typeHandle) || RuntimeAugments.IsByRefType(_typeHandle); - } - - protected override bool IsArrayImpl() - { - return RuntimeAugments.IsArrayType(_typeHandle); - } - - protected override bool IsByRefImpl() - { - return RuntimeAugments.IsByRefType(_typeHandle); - } - - protected override bool IsPointerImpl() - { - return RuntimeAugments.IsUnmanagedPointerType(_typeHandle); - } - - protected override bool IsPrimitiveImpl() - { - return RuntimeAugments.IsPrimitive(_typeHandle); - } - - public override bool IsAssignableFrom([NotNullWhen(true)] Type c) - { - if (c == null) - return false; - - if (object.ReferenceEquals(c, this)) - return true; - - c = c.UnderlyingSystemType; - - Type typeInfo = c; - RuntimeTypeInfo toTypeInfo = this; - - if (typeInfo is not RuntimeType) - return false; // Desktop compat: If typeInfo is null, or implemented by a different Reflection implementation, return "false." - - // !!!??? - RuntimeTypeInfo fromTypeInfo = (RuntimeTypeInfo)typeInfo; - - RuntimeTypeHandle toTypeHandle = toTypeInfo._typeHandle; - RuntimeTypeHandle fromTypeHandle = fromTypeInfo._typeHandle; - - if (RuntimeAugments.IsGenericTypeDefinition(toTypeHandle) || RuntimeAugments.IsGenericTypeDefinition(fromTypeHandle)) - throw new NotSupportedException(SR.Reflection_Disabled); - - if (RuntimeAugments.IsAssignableFrom(toTypeHandle, fromTypeHandle)) - return true; - - return false; - } - - internal static RuntimeTypeInfo GetRuntimeTypeInfo(RuntimeTypeHandle typeHandle) - { - return RuntimeTypeTable.Table.GetOrAdd(new RuntimeTypeHandleKey(typeHandle)); - } - - [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 - if (IsPrimitive) - { - if (this == typeof(sbyte)) - return typeof(sbyte[]); - else if (this == typeof(byte)) - return typeof(byte[]); - else if (this == typeof(short)) - return typeof(short[]); - else if (this == typeof(ushort)) - return typeof(ushort[]); - else if (this == typeof(int)) - return typeof(int[]); - else if (this == typeof(uint)) - return typeof(uint[]); - else if (this == typeof(long)) - return typeof(long[]); - else if (this == typeof(ulong)) - return typeof(ulong[]); - } - - return base.MakeArrayType(); - } - - private sealed class RuntimeTypeTable : ConcurrentUnifierW - { - protected sealed override RuntimeTypeInfo Factory(RuntimeTypeHandleKey key) - { - return new RuntimeTypeInfo(key.TypeHandle); - } - - public static readonly RuntimeTypeTable Table = new RuntimeTypeTable(); - } - - internal struct RuntimeTypeHandleKey : IEquatable - { - public RuntimeTypeHandleKey(RuntimeTypeHandle typeHandle) - { - TypeHandle = typeHandle; - } - - public RuntimeTypeHandle TypeHandle { get; } - - public override bool Equals(object obj) - { - if (!(obj is RuntimeTypeHandleKey other)) - return false; - return Equals(other); - } - - public bool Equals(RuntimeTypeHandleKey other) - { - return TypeHandle.Equals(other.TypeHandle); - } - - public override int GetHashCode() - { - return TypeHandle.GetHashCode(); - } - } - - internal const DynamicallyAccessedMemberTypes GetAllMembers = DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | - DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | - DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.NonPublicEvents | - DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | - DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | - DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicNestedTypes; - } -} diff --git a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Runtime/CompilerHelpers/LibraryInitializer.cs b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Runtime/CompilerHelpers/LibraryInitializer.cs deleted file mode 100644 index 9a402f3b20656..0000000000000 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Runtime/CompilerHelpers/LibraryInitializer.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Internal.Reflection; -using Internal.Reflection.Augments; -using Internal.Runtime.Augments; - -namespace Internal.Runtime.CompilerHelpers -{ - public class LibraryInitializer - { - public static void InitializeLibrary() - { - RuntimeAugments.Initialize(new ReflectionExecutionDomainCallbacksImplementation()); - ReflectionAugments.Initialize(new ReflectionCoreCallbacksImplementation()); - } - } -} diff --git a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Resources/Strings.resx b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Resources/Strings.resx deleted file mode 100644 index ee0f58a933adf..0000000000000 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/Resources/Strings.resx +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table. - - - This operation is not available because the reflection support was disabled at compile time. - - diff --git a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/System.Private.DisabledReflection.csproj b/src/coreclr/nativeaot/System.Private.DisabledReflection/src/System.Private.DisabledReflection.csproj deleted file mode 100644 index b13f9130c97f8..0000000000000 --- a/src/coreclr/nativeaot/System.Private.DisabledReflection/src/System.Private.DisabledReflection.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - false - - - - - - - System\Collections\Concurrent\ConcurrentUnifierW.cs - - - System\Collections\HashHelpers.cs - - - - - diff --git a/src/coreclr/nativeaot/nativeaot.sln b/src/coreclr/nativeaot/nativeaot.sln index 7812cd25d4925..e1b0efe3a33db 100644 --- a/src/coreclr/nativeaot/nativeaot.sln +++ b/src/coreclr/nativeaot/nativeaot.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.30421.15 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.CoreLib", "System.Private.CoreLib\src\System.Private.CoreLib.csproj", "{E4BC768B-F97D-4A8F-9391-B65DF3EB47C6}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.DisabledReflection", "System.Private.DisabledReflection\src\System.Private.DisabledReflection.csproj", "{ADA691AE-4E1F-4212-97E6-51A27EFCE7E4}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.Reflection.Execution", "System.Private.Reflection.Execution\src\System.Private.Reflection.Execution.csproj", "{7498DD7C-76C1-4912-AF72-DA84E05B568F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.StackTraceMetadata", "System.Private.StackTraceMetadata\src\System.Private.StackTraceMetadata.csproj", "{33CAE331-16EE-443C-A0CC-4337B94A02AD}" diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index aea7e2e5d2af6..685293c97058d 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -144,7 +144,6 @@ - diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 540dc62f30918..c7bd356446cf4 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -4274,4 +4274,7 @@ Unsupported type - \ No newline at end of file + + This operation is not available because the reflection support was disabled at compile time. + +