Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ protected CustomAttributeData()
Justification = "Property setters and fields which are accessed by any attribute instantiation which is present in the code linker has analyzed." +
"As such enumerating all fields and properties may return different results after trimming" +
"but all those which are needed to actually have data will be there.")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern",
Justification = "We're getting a MethodBase of a constructor that we found in the metadata. The attribute constructor won't be trimmed.")]
private CustomAttributeData(RuntimeModule scope, MetadataToken caCtorToken, in ConstArray blob)
{
m_scope = scope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1305,8 +1305,11 @@ private static void ValidateModulePointer(RuntimeModule module)
}

// SQL-CLR LKG9 Compiler dependency
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken(int typeToken) { return ResolveTypeHandle(typeToken); }
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeTypeHandle ResolveTypeHandle(int typeToken) => ResolveTypeHandle(typeToken, null, null);
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
{
RuntimeModule module = GetRuntimeModule();
Expand Down Expand Up @@ -1359,8 +1362,11 @@ private static extern void ResolveType(QCallModule module,
ObjectHandleOnStack type);

// SQL-CLR LKG9 Compiler dependency
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeMethodHandle GetRuntimeMethodHandleFromMetadataToken(int methodToken) { return ResolveMethodHandle(methodToken); }
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeMethodHandle ResolveMethodHandle(int methodToken) => ResolveMethodHandle(methodToken, null, null);
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
{
RuntimeModule module = GetRuntimeModule();
Expand Down Expand Up @@ -1407,8 +1413,11 @@ private static extern RuntimeMethodHandleInternal ResolveMethod(QCallModule modu
int methodInstCount);

// SQL-CLR LKG9 Compiler dependency
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeFieldHandle GetRuntimeFieldHandleFromMetadataToken(int fieldToken) { return ResolveFieldHandle(fieldToken); }
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeFieldHandle ResolveFieldHandle(int fieldToken) => ResolveFieldHandle(fieldToken, null, null);
[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeFieldHandle ResolveFieldHandle(int fieldToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
{
RuntimeModule module = GetRuntimeModule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,10 @@ private RuntimeType[] PopulateInterfaces(Filter filter)
return list.ToArray();
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern",
Justification = "Calls to ResolveTypeHandle technically require all types to be kept " +
"But this is not a public API to enumerate reflection items, all the public APIs which do that " +
"should be annotated accordingly.")]
private RuntimeType[] PopulateNestedClasses(Filter filter)
{
RuntimeType declaringType = ReflectedType;
Expand Down Expand Up @@ -1733,6 +1737,7 @@ internal FieldInfo GetField(RuntimeFieldHandleInternal field)
typeName, throwOnError, ignoreCase, ref stackMark);
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
internal static MethodBase? GetMethodBase(RuntimeModule scope, int typeMetadataToken)
{
return GetMethodBase(new ModuleHandle(scope).ResolveMethodHandle(typeMetadataToken).GetMethodInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static partial class Activator
// Note: CreateInstance returns null for Nullable<T>, e.g. CreateInstance(typeof(int?)) returns null.
//

public static object? CreateInstance(Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes)
public static object? CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes)
{
if (type is null)
throw new ArgumentNullException(nameof(type));
Expand All @@ -39,6 +39,7 @@ public static partial class Activator
}

[System.Security.DynamicSecurityMethod]
[RequiresUnreferencedCode("Type and its constructor could be removed")]
public static ObjectHandle? CreateInstance(string assemblyName, string typeName)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
Expand All @@ -54,6 +55,7 @@ public static partial class Activator
}

[System.Security.DynamicSecurityMethod]
[RequiresUnreferencedCode("Type and its constructor could be removed")]
public static ObjectHandle? CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
Expand All @@ -69,6 +71,7 @@ public static partial class Activator
}

[System.Security.DynamicSecurityMethod]
[RequiresUnreferencedCode("Type and its constructor could be removed")]
public static ObjectHandle? CreateInstance(string assemblyName, string typeName, object?[]? activationAttributes)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
Expand Down
14 changes: 13 additions & 1 deletion src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,18 @@ public AccessViolationException(string? message, System.Exception? innerExceptio
public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
public static partial class Activator
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Type and its constructor could be removed")]
public static System.Runtime.Remoting.ObjectHandle? CreateInstance(string assemblyName, string typeName) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Type and its constructor could be removed")]
public static System.Runtime.Remoting.ObjectHandle? CreateInstance(string assemblyName, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Type and its constructor could be removed")]
public static System.Runtime.Remoting.ObjectHandle? CreateInstance(string assemblyName, string typeName, object?[]? activationAttributes) { throw null; }
public static object? CreateInstance([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type type) { throw null; }
public static object? CreateInstance([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type, bool nonPublic) { throw null; }
public static object? CreateInstance([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type, params object?[]? args) { throw null; }
public static object? CreateInstance([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type, object?[]? args, object?[]? activationAttributes) { throw null; }
public static object? CreateInstance([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture) { throw null; }
public static object? CreateInstance(System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes) { throw null; }
public static object? CreateInstance([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Type and its constructor could be removed")]
public static System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Type and its constructor could be removed")]
Expand Down Expand Up @@ -3015,16 +3018,25 @@ public partial struct ModuleHandle
public bool Equals(System.ModuleHandle handle) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public override int GetHashCode() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeFieldHandle GetRuntimeFieldHandleFromMetadataToken(int fieldToken) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeMethodHandle GetRuntimeMethodHandleFromMetadataToken(int methodToken) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken(int typeToken) { throw null; }
public static bool operator ==(System.ModuleHandle left, System.ModuleHandle right) { throw null; }
public static bool operator !=(System.ModuleHandle left, System.ModuleHandle right) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeFieldHandle ResolveFieldHandle(int fieldToken) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeFieldHandle ResolveFieldHandle(int fieldToken, System.RuntimeTypeHandle[]? typeInstantiationContext, System.RuntimeTypeHandle[]? methodInstantiationContext) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeMethodHandle ResolveMethodHandle(int methodToken) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeMethodHandle ResolveMethodHandle(int methodToken, System.RuntimeTypeHandle[]? typeInstantiationContext, System.RuntimeTypeHandle[]? methodInstantiationContext) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeTypeHandle ResolveTypeHandle(int typeToken) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Trimming changes metadata tokens")]
public System.RuntimeTypeHandle ResolveTypeHandle(int typeToken, System.RuntimeTypeHandle[]? typeInstantiationContext, System.RuntimeTypeHandle[]? methodInstantiationContext) { throw null; }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Method)]
Expand Down
9 changes: 9 additions & 0 deletions src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ public int MDStreamVersion
}
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeFieldHandle ResolveFieldHandle(int fieldToken)
{
return ResolveFieldHandle(fieldToken, null, null);
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeMethodHandle ResolveMethodHandle(int methodToken)
{
return ResolveMethodHandle(methodToken, null, null);
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeTypeHandle ResolveTypeHandle(int typeToken)
{
return ResolveTypeHandle(typeToken, null, null);
Expand All @@ -61,6 +64,7 @@ public RuntimeTypeHandle ResolveTypeHandle(int typeToken)
return res;
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
{
ResolveTokenError error;
Expand All @@ -73,6 +77,7 @@ public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[]? t
return new RuntimeTypeHandle(res);
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
{
ResolveTokenError error;
Expand All @@ -85,6 +90,7 @@ public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandl
return new RuntimeMethodHandle(res);
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeFieldHandle ResolveFieldHandle(int fieldToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext)
{
ResolveTokenError error;
Expand All @@ -98,16 +104,19 @@ public RuntimeFieldHandle ResolveFieldHandle(int fieldToken, RuntimeTypeHandle[]
return new RuntimeFieldHandle(res);
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeFieldHandle GetRuntimeFieldHandleFromMetadataToken(int fieldToken)
{
return ResolveFieldHandle(fieldToken);
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeMethodHandle GetRuntimeMethodHandleFromMetadataToken(int methodToken)
{
return ResolveMethodHandle(methodToken);
}

[RequiresUnreferencedCode("Trimming changes metadata tokens")]
public RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken(int typeToken)
{
return ResolveTypeHandle(typeToken);
Expand Down