diff --git a/eng/DefaultGenApiDocIds.txt b/eng/DefaultGenApiDocIds.txt
index 22d8d211831aea..5576d9fad6ae21 100644
--- a/eng/DefaultGenApiDocIds.txt
+++ b/eng/DefaultGenApiDocIds.txt
@@ -7,6 +7,7 @@ T:System.ComponentModel.EditorAttribute
T:System.ComponentModel.ToolboxItemAttribute
T:System.ComponentModel.TypeDescriptionProviderAttribute
T:System.Configuration.ConfigurationPropertyAttribute
+T:System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute
T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute
T:System.Diagnostics.CodeAnalysis.MemberNotNullAttribute
T:System.Diagnostics.CodeAnalysis.SuppressMessageAttribute
@@ -27,7 +28,6 @@ T:System.Runtime.CompilerServices.IteratorStateMachineAttribute
T:System.Runtime.CompilerServices.MethodImpl
T:System.Runtime.CompilerServices.NullableAttribute
T:System.Runtime.CompilerServices.NullableContextAttribute
-T:System.Runtime.CompilerServices.PreserveDependencyAttribute
T:System.Runtime.CompilerServices.TypeForwardedFromAttribute
T:System.Runtime.ConstrainedExecution.PrePrepareMethodAttribute
T:System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
diff --git a/eng/illink.targets b/eng/illink.targets
index 106b7126f21c7b..af7c435d3d966b 100644
--- a/eng/illink.targets
+++ b/eng/illink.targets
@@ -142,7 +142,7 @@
$(ILLinkArgs) --skip-unresolved true
$(ILLinkArgs) --disable-opt unusedinterfaces
-
+
$(ILLinkArgs) --keep-dep-attributes true
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs
index f8dfb2780fe26d..9cdc04e45f3886 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.CoreCLR.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
namespace System.Collections.Generic
{
@@ -20,7 +21,7 @@ internal partial class ArraySortHelper
public static IArraySortHelper Default => s_defaultArraySortHelper;
- [PreserveDependency(".ctor", "System.Collections.Generic.GenericArraySortHelper`1")]
+ [DynamicDependency("#ctor", typeof(GenericArraySortHelper<>))]
private static IArraySortHelper CreateArraySortHelper()
{
IArraySortHelper defaultArraySortHelper;
@@ -55,7 +56,7 @@ internal partial class ArraySortHelper
public static IArraySortHelper Default => s_defaultArraySortHelper;
- [PreserveDependency(".ctor", "System.Collections.Generic.GenericArraySortHelper`2")]
+ [DynamicDependency("#ctor", typeof(GenericArraySortHelper<,>))]
private static IArraySortHelper CreateArraySortHelper()
{
IArraySortHelper defaultArraySortHelper;
diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs
index 41b1dd72e01023..be31abad855c32 100644
--- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs
+++ b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs
@@ -4,7 +4,7 @@
using System.Threading;
using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
namespace System.Diagnostics
{
@@ -84,12 +84,13 @@ public StackFrameHelper(Thread? target)
// done by GetStackFramesInternal (on Windows for old PDB format).
//
+ // TODO: Remove these DynamicDependencyAttributes when https://github.com/mono/linker/issues/943 is fixed.
// This is necessary because linker can't add new assemblies to the closure when recognizing Type.GetType
// so the code below is actually recognized by linker, but fails to resolve the type since the System.Diagnostics.StackTrace
// is not always part of the closure linker works on.
- // PreserveDependencyAttribute on the other hand can pull in additional assemblies.
- [PreserveDependency("GetSourceLineInfo", "System.Diagnostics.StackTraceSymbols", "System.Diagnostics.StackTrace")]
- [PreserveDependency(".ctor()", "System.Diagnostics.StackTraceSymbols", "System.Diagnostics.StackTrace")]
+ // DynamicDependencyAttribute on the other hand can pull in additional assemblies.
+ [DynamicDependency("GetSourceLineInfo", "System.Diagnostics.StackTraceSymbols", "System.Diagnostics.StackTrace")]
+ [DynamicDependency("#ctor()", "System.Diagnostics.StackTraceSymbols", "System.Diagnostics.StackTrace")]
internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception? exception)
{
StackTrace.GetStackFramesInternal(this, iSkip, fNeedFileInfo, exception);
diff --git a/src/libraries/Common/src/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs b/src/libraries/Common/src/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs
deleted file mode 100644
index 6d04e94119eac7..00000000000000
--- a/src/libraries/Common/src/System/Runtime/CompilerServices/PreserveDependencyAttribute.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-#nullable enable
-
-// TODO https://github.com/dotnet/runtime/issues/30902: Design and expose this publicly.
-
-namespace System.Runtime.CompilerServices
-{
- /// States a dependency that one member has on another.
- ///
- /// This can be used to inform tooling of a dependency that is otherwise not evident purely from
- /// metadata and IL, for example a member relied on via reflection.
- ///
- [AttributeUsage(
- AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field /* AttributeTargets.Class | AttributeTargets.Struct */, // TODO: https://github.com/mono/linker/issues/797
- AllowMultiple = true, Inherited = false)]
- internal sealed class PreserveDependencyAttribute : Attribute
- {
- /// Initializes the attribute.
- /// The signature of the member depended.
- public PreserveDependencyAttribute(string memberSignature)
- {
- MemberSignature = memberSignature;
- }
-
- /// Initializes the attribute.
- /// The signature of the member depended on.
- /// The full name of the type containing .
- public PreserveDependencyAttribute(string memberSignature, string typeName)
- {
- MemberSignature = memberSignature;
- TypeName = typeName;
- }
-
- /// Initializes the attribute.
- /// The signature of the member depended on.
- /// The full name of the type containing .
- /// The name of the assembly containing .
- public PreserveDependencyAttribute(string memberSignature, string typeName, string assemblyName)
- {
- MemberSignature = memberSignature;
- TypeName = typeName;
- AssemblyName = assemblyName;
- }
-
- /// Gets the signature of the member depended on.
- public string MemberSignature { get; }
-
- /// Gets the full name of the type containing the specified member.
- /// If no type name is specified, the type of the consumer is assumed.
- public string? TypeName { get; }
-
- /// Gets the assembly name of the specified type.
- /// If no assembly name is specified, the assembly of the consumer is assumed.
- public string? AssemblyName { get; }
-
- /// Gets or sets the condition in which the dependency is applicable, e.g. "DEBUG".
- public string? Condition { get; set; }
- }
-}
diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System.ComponentModel.TypeConverter.csproj b/src/libraries/System.ComponentModel.TypeConverter/src/System.ComponentModel.TypeConverter.csproj
index 9b57a22eee4b24..f4869cbbb261c8 100644
--- a/src/libraries/System.ComponentModel.TypeConverter/src/System.ComponentModel.TypeConverter.csproj
+++ b/src/libraries/System.ComponentModel.TypeConverter/src/System.ComponentModel.TypeConverter.csproj
@@ -237,8 +237,6 @@
-
diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs
index 353bef276e2415..0834922d1f5115 100644
--- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs
+++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs
@@ -10,7 +10,6 @@
using System.Globalization;
using System.Linq;
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Threading;
namespace System.ComponentModel
@@ -87,7 +86,8 @@ private TypeDescriptor()
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static Type InterfaceType
{
- [PreserveDependency(".ctor", "System.ComponentModel.TypeDescriptor/TypeDescriptorInterface")]
+ // TODO: replace this with DynamicallyAccessedMembersAttribute (https://github.com/dotnet/runtime/issues/37837)
+ [DynamicDependency("#ctor", typeof(TypeDescriptorInterface))]
get => typeof(TypeDescriptorInterface);
}
diff --git a/src/libraries/System.Data.Common/src/System.Data.Common.csproj b/src/libraries/System.Data.Common/src/System.Data.Common.csproj
index a9583ce2d19146..c30c7703820514 100644
--- a/src/libraries/System.Data.Common/src/System.Data.Common.csproj
+++ b/src/libraries/System.Data.Common/src/System.Data.Common.csproj
@@ -294,8 +294,6 @@
-
diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SqlXml.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SqlXml.cs
index 02baf8afcd2d67..a1f4c409c3b1bb 100644
--- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SqlXml.cs
+++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SqlXml.cs
@@ -10,7 +10,7 @@
using System.Diagnostics;
using System.Text;
using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
namespace System.Data.SqlTypes
{
@@ -128,7 +128,7 @@ private static Func Crea
private static MethodInfo CreateSqlReaderMethodInfo
{
- [PreserveDependency("CreateSqlReader", "System.Xml.XmlReader", "System.Private.Xml")]
+ [DynamicDependency("CreateSqlReader", typeof(System.Xml.XmlReader))]
get
{
if (s_createSqlReaderMethodInfo == null)
diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
index e3bb30d9cea2bc..4619c9519c840d 100644
--- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
+++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
@@ -25,11 +25,13 @@
-
-
+
+
+
+
+
@@ -46,10 +48,10 @@
-
+
-
+
diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
index e8ea5d3233e569..0c3d619900a3e0 100644
--- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
+++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Concurrent;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Tracing;
using System.Reflection;
using System.Runtime.CompilerServices;
@@ -891,9 +892,9 @@ public PropertyFetch(Type? type)
///
/// Create a property fetcher for a propertyName
///
- [PreserveDependency(".ctor(System.Type)", "System.Diagnostics.DiagnosticSourceEventSource/TransformSpec/PropertySpec/PropertyFetch/EnumeratePropertyFetch`1")]
- [PreserveDependency(".ctor(System.Type, System.Reflection.PropertyInfo)", "System.Diagnostics.DiagnosticSourceEventSource/TransformSpec/PropertySpec/PropertyFetch/RefTypedFetchProperty`2")]
- [PreserveDependency(".ctor(System.Type, System.Reflection.PropertyInfo)", "System.Diagnostics.DiagnosticSourceEventSource/TransformSpec/PropertySpec/PropertyFetch/ValueTypedFetchProperty`2")]
+ [DynamicDependency("#ctor(System.Type)", typeof(EnumeratePropertyFetch<>))]
+ [DynamicDependency("#ctor(System.Type,System.Reflection.PropertyInfo)", typeof(RefTypedFetchProperty<,>))]
+ [DynamicDependency("#ctor(System.Type,System.Reflection.PropertyInfo)", typeof(ValueTypedFetchProperty<,>))]
public static PropertyFetch FetcherForProperty(Type? type, string propertyName)
{
if (propertyName == null)
diff --git a/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj b/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj
index c9c9624cc3c946..8e8462ac62ea2a 100644
--- a/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj
+++ b/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj
@@ -15,8 +15,6 @@
-
diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.Generated.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.Generated.cs
index fd016ce1c3e2eb..ed2ee838c56bc2 100644
--- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.Generated.cs
+++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.Generated.cs
@@ -7,7 +7,7 @@
using System.Dynamic;
using System.Dynamic.Utils;
using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace System.Linq.Expressions.Interpreter
@@ -160,16 +160,17 @@ private static CallInstruction FastCreate(MethodInfo target, ParameterIn
#endif
#if FEATURE_DLG_INVOKE
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.ActionCallInstruction")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.ActionCallInstruction`1")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.ActionCallInstruction`2")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.ActionCallInstruction`3")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.ActionCallInstruction`4")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.FuncCallInstruction`1")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.FuncCallInstruction`2")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.FuncCallInstruction`3")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.FuncCallInstruction`4")]
- [PreserveDependency(".ctor", "System.Linq.Expressions.Interpreter.FuncCallInstruction`5")]
+ // TODO: replace these with DynamicallyAccessedMembersAttribute (https://github.com/dotnet/runtime/issues/37837)
+ [DynamicDependency("#ctor", typeof(ActionCallInstruction))]
+ [DynamicDependency("#ctor", typeof(ActionCallInstruction<>))]
+ [DynamicDependency("#ctor", typeof(ActionCallInstruction<,>))]
+ [DynamicDependency("#ctor", typeof(ActionCallInstruction<,,>))]
+ [DynamicDependency("#ctor", typeof(ActionCallInstruction<,,,>))]
+ [DynamicDependency("#ctor", typeof(FuncCallInstruction<>))]
+ [DynamicDependency("#ctor", typeof(FuncCallInstruction<,>))]
+ [DynamicDependency("#ctor", typeof(FuncCallInstruction<,,>))]
+ [DynamicDependency("#ctor", typeof(FuncCallInstruction<,,,>))]
+ [DynamicDependency("#ctor", typeof(FuncCallInstruction<,,,,>))]
private static Type GetHelperType(MethodInfo info, Type[] arrTypes)
{
Type t;
diff --git a/src/libraries/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSite.cs b/src/libraries/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSite.cs
index 7c0116acbd2814..6c8d59c5a7802d 100644
--- a/src/libraries/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSite.cs
+++ b/src/libraries/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSite.cs
@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Dynamic.Utils;
using System.Linq.Expressions;
@@ -275,47 +276,7 @@ internal void MoveRule(int i)
}
#if FEATURE_COMPILE
- // TODO https://github.com/mono/linker/issues/799: Consolidate these attributes when possible.
- [PreserveDependency("NoMatch1`2", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch2`3", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch3`4", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch4`5", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch5`6", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch6`7", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch7`8", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch8`9", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch9`10", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatch10`11", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid1`1", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid2`2", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid3`3", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid4`4", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid5`5", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid6`6", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid7`7", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid8`8", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid9`9", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("NoMatchVoid10`10", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute1`2", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute2`3", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute3`4", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute4`5", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute5`6", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute6`7", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute7`8", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute8`9", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute9`10", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecute10`11", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid1`1", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid2`2", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid3`3", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid4`4", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid5`5", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid6`6", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid7`7", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid8`8", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid9`9", "System.Dynamic.UpdateDelegates")]
- [PreserveDependency("UpdateAndExecuteVoid10`10", "System.Dynamic.UpdateDelegates")]
+ [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(UpdateDelegates))]
#endif
internal T MakeUpdateDelegate()
{
diff --git a/src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj b/src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj
index b27d2d05646c7f..17a49ab20c2d7f 100644
--- a/src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj
+++ b/src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj
@@ -83,8 +83,6 @@
-
diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/CookieExtensions.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/CookieExtensions.cs
index d1af32d24973fa..3543dffbfbc126 100644
--- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/CookieExtensions.cs
+++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/CookieExtensions.cs
@@ -4,7 +4,7 @@
using System.Diagnostics;
using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
namespace System.Net
{
@@ -13,7 +13,7 @@ internal static class CookieExtensions
{
private static Func s_toServerStringFunc;
- [PreserveDependency("ToServerString", "System.Net.Cookie", "System.Net.Primitives")]
+ [DynamicDependency("ToServerString", typeof(Cookie))]
public static string ToServerString(this Cookie cookie)
{
s_toServerStringFunc ??= (Func)typeof(Cookie).GetMethod("ToServerString", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(Func));
@@ -23,7 +23,7 @@ public static string ToServerString(this Cookie cookie)
private static Func s_cloneFunc;
- [PreserveDependency("Clone", "System.Net.Cookie", "System.Net.Primitives")]
+ [DynamicDependency("Clone", typeof(Cookie))]
public static Cookie Clone(this Cookie cookie)
{
s_cloneFunc ??= (Func)typeof(Cookie).GetMethod("Clone", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(Func));
@@ -42,7 +42,7 @@ private enum CookieVariant
private static Func s_getVariantFunc;
- [PreserveDependency("get_Variant", "System.Net.Cookie", "System.Net.Primitives")]
+ [DynamicDependency("get_Variant", typeof(Cookie))]
public static bool IsRfc2965Variant(this Cookie cookie)
{
s_getVariantFunc ??= (Func)typeof(Cookie).GetProperty("Variant", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(true).CreateDelegate(typeof(Func));
@@ -55,7 +55,7 @@ internal static class CookieCollectionExtensions
{
private static Func s_internalAddFunc;
- [PreserveDependency("InternalAdd", "System.Net.CookieCollection", "System.Net.Primitives")]
+ [DynamicDependency("InternalAdd", typeof(CookieCollection))]
public static int InternalAdd(this CookieCollection cookieCollection, Cookie cookie, bool isStrict)
{
s_internalAddFunc ??= (Func)typeof(CookieCollection).GetMethod("InternalAdd", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(Func));
diff --git a/src/libraries/System.Net.Primitives/src/System.Net.Primitives.csproj b/src/libraries/System.Net.Primitives/src/System.Net.Primitives.csproj
index 336460cdd13268..8fd75e869d6856 100644
--- a/src/libraries/System.Net.Primitives/src/System.Net.Primitives.csproj
+++ b/src/libraries/System.Net.Primitives/src/System.Net.Primitives.csproj
@@ -76,8 +76,6 @@
Link="Common\System\Marvin.cs" />
-
diff --git a/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs b/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs
index b514d78d65201f..c362da13e751c9 100644
--- a/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs
+++ b/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs
@@ -7,7 +7,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
-using System.Runtime.CompilerServices;
using System.Text;
namespace System.Net
@@ -80,24 +79,24 @@ static Cookie()
}
#endif
- // These PreserveDependency attributes are a workaround for https://github.com/dotnet/runtime/issues/19348.
+ // These DynamicDependency attributes are a workaround for https://github.com/dotnet/runtime/issues/19348.
// HttpListener uses the non-public ToServerString, which isn't used by anything else in this assembly,
// and which accesses other internals and can't be moved to HttpListener (at least not without incurring
// functional differences). However, once we do our initial System.Net.Primitives build and ToServerString
- // survives to it, we no longer want the PreserveDependencyAttribute to remain around, so that ToServerString
+ // survives to it, we no longer want the DynamicDependencyAttribute to remain around, so that ToServerString
// can be trimmed out if the relevant functionality from HttpListener isn't used when performing whole-app
// analysis. As such, when trimming System.Net.Primitives, we build the assembly with ILLinkKeepDepAttributes=false,
- // such that when this assembly is compiled, ToServerString will remain but the PreserveDependency attributes
+ // such that when this assembly is compiled, ToServerString will remain but the DynamicDependency attributes
// will be removed. This hack will need to be revisited if anything else in the assembly starts using
- // PreserveDependencyAttribute.
+ // DynamicDependencyAttribute.
// https://github.com/mono/linker/issues/802
- [PreserveDependency("ToServerString")]
+ [DynamicDependency("ToServerString")]
public Cookie()
{
}
- [PreserveDependency("ToServerString")] // Workaround for https://github.com/dotnet/runtime/issues/19348
+ [DynamicDependency("ToServerString")] // Workaround for https://github.com/dotnet/runtime/issues/19348
public Cookie(string name, string? value)
{
Name = name;
diff --git a/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj b/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj
index a88f09f865e9ea..1f1eddf8e048d0 100644
--- a/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj
+++ b/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj
@@ -45,8 +45,6 @@
Link="ProductionCode\System\Net\SocketException.cs" />
-
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 1e9f20c2943119..e0f887b270d05e 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -1101,9 +1101,6 @@
Common\System\IO\StreamHelpers.CopyValidation.cs
-
- Common\System\Runtime\CompilerServices\PreserveDependencyAttribute.cs
-
Common\System\Runtime\Versioning\NonVersionableAttribute.cs
diff --git a/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs b/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs
index 7f3fbf44ca766d..ece07a82d78886 100644
--- a/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs
@@ -8,7 +8,6 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.Loader;
using System.Runtime.Remoting;
@@ -405,8 +404,9 @@ public void SetThreadPrincipal(IPrincipal principal)
return oh?.Unwrap();
}
- [PreserveDependency("GetDefaultInstance", "System.Security.Principal.GenericPrincipal", "System.Security.Claims")]
- [PreserveDependency("GetDefaultInstance", "System.Security.Principal.WindowsPrincipal", "System.Security.Principal.Windows")]
+ // TODO: Remove these DynamicDependencyAttributes when https://github.com/mono/linker/issues/943 is fixed.
+ [DynamicDependency("GetDefaultInstance", "System.Security.Principal.GenericPrincipal", "System.Security.Claims")]
+ [DynamicDependency("GetDefaultInstance", "System.Security.Principal.WindowsPrincipal", "System.Security.Principal.Windows")]
internal IPrincipal? GetThreadPrincipal()
{
IPrincipal? principal = _defaultPrincipal;
diff --git a/src/libraries/System.Private.CoreLib/src/System/ComponentModel/DefaultValueAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/ComponentModel/DefaultValueAttribute.cs
index 044d05949fe047..0476feba6a30ee 100644
--- a/src/libraries/System.Private.CoreLib/src/System/ComponentModel/DefaultValueAttribute.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/ComponentModel/DefaultValueAttribute.cs
@@ -2,9 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Threading;
namespace System.ComponentModel
@@ -29,7 +29,7 @@ public class DefaultValueAttribute : Attribute
/// culture as the translation context.
///
// TODO: https://github.com/mono/linker/issues/943
- [PreserveDependency("ConvertFromInvariantString", "System.ComponentModel.TypeConverter", "System.ComponentModel.TypeConverter")]
+ [DynamicDependency("ConvertFromInvariantString", "System.ComponentModel.TypeConverter", "System.ComponentModel.TypeConverter")]
public DefaultValueAttribute(Type type, string? value)
{
// The null check and try/catch here are because attributes should never throw exceptions.
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicDependencyAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicDependencyAttribute.cs
index 8c730d2fb6abda..4b7571cc902bbd 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicDependencyAttribute.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicDependencyAttribute.cs
@@ -14,7 +14,12 @@ namespace System.Diagnostics.CodeAnalysis
[AttributeUsage(
AttributeTargets.Constructor | AttributeTargets.Field | AttributeTargets.Method,
AllowMultiple = true, Inherited = false)]
- public sealed class DynamicDependencyAttribute : Attribute
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ sealed class DynamicDependencyAttribute : Attribute
{
///
/// Initializes a new instance of the class
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMemberTypes.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMemberTypes.cs
index 965fe539a94377..ab245178cdd859 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMemberTypes.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/DynamicallyAccessedMemberTypes.cs
@@ -11,7 +11,12 @@ namespace System.Diagnostics.CodeAnalysis
/// bitwise combination of its member values.
///
[Flags]
- public enum DynamicallyAccessedMemberTypes
+#if SYSTEM_PRIVATE_CORELIB
+ public
+#else
+ internal
+#endif
+ enum DynamicallyAccessedMemberTypes
{
///
/// Specifies no members.
diff --git a/src/libraries/System.Private.CoreLib/src/System/String.cs b/src/libraries/System.Private.CoreLib/src/System/String.cs
index 00582d5ebca437..b5922eaa9d78e1 100644
--- a/src/libraries/System.Private.CoreLib/src/System/String.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/String.cs
@@ -46,7 +46,7 @@ public sealed partial class String : IComparable, IEnumerable, IConvertible, IEn
*/
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.Char[])", "System.String")]
+ [DynamicDependency("Ctor(System.Char[])")]
public extern String(char[]? value);
private
@@ -69,7 +69,7 @@ string Ctor(char[]? value)
}
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.Char[],System.Int32,System.Int32)", "System.String")]
+ [DynamicDependency("Ctor(System.Char[],System.Int32,System.Int32)")]
public extern String(char[] value, int startIndex, int length);
private
@@ -105,7 +105,7 @@ string Ctor(char[] value, int startIndex, int length)
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.Char*)", "System.String")]
+ [DynamicDependency("Ctor(System.Char*)")]
public extern unsafe String(char* value);
private
@@ -133,7 +133,7 @@ unsafe string Ctor(char* ptr)
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.Char*,System.Int32,System.Int32)", "System.String")]
+ [DynamicDependency("Ctor(System.Char*,System.Int32,System.Int32)")]
public extern unsafe String(char* value, int startIndex, int length);
private
@@ -172,7 +172,7 @@ unsafe string Ctor(char* ptr, int startIndex, int length)
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.SByte*)", "System.String")]
+ [DynamicDependency("Ctor(System.SByte*)")]
public extern unsafe String(sbyte* value);
private
@@ -192,7 +192,7 @@ unsafe string Ctor(sbyte* value)
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.SByte*,System.Int32,System.Int32)", "System.String")]
+ [DynamicDependency("Ctor(System.SByte*,System.Int32,System.Int32)")]
public extern unsafe String(sbyte* value, int startIndex, int length);
private
@@ -253,7 +253,7 @@ private static unsafe string CreateStringForSByteConstructor(byte* pb, int numBy
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.SByte*,System.Int32,System.Int32,System.Text.Encoding)", "System.String")]
+ [DynamicDependency("Ctor(System.SByte*,System.Int32,System.Int32,System.Text.Encoding)")]
public extern unsafe String(sbyte* value, int startIndex, int length, Encoding enc);
private
@@ -289,7 +289,7 @@ unsafe string Ctor(sbyte* value, int startIndex, int length, Encoding? enc)
}
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.Char,System.Int32)", "System.String")]
+ [DynamicDependency("Ctor(System.Char,System.Int32)")]
public extern String(char c, int count);
private
@@ -340,7 +340,7 @@ string Ctor(char c, int count)
}
[MethodImpl(MethodImplOptions.InternalCall)]
- [PreserveDependency("Ctor(System.ReadOnlySpan`1)", "System.String")]
+ [DynamicDependency("Ctor(System.ReadOnlySpan{System.Char})")]
public extern String(ReadOnlySpan value);
private
diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj
index 0dce72cc7b798b..09085154127352 100644
--- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj
+++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj
@@ -18,7 +18,6 @@
$(NoWarn);nullable
-
@@ -237,6 +236,10 @@
+
+
+
+
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs
index 1a58ed83cda94e..56012689bc5e66 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverterFactory.cs
@@ -6,8 +6,8 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
-using System.Runtime.CompilerServices;
namespace System.Text.Json.Serialization.Converters
{
@@ -25,23 +25,23 @@ public override bool CanConvert(Type typeToConvert)
return typeof(IEnumerable).IsAssignableFrom(typeToConvert);
}
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ArrayConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ConcurrentQueueOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ConcurrentStackOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.DictionaryOfStringTValueConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ICollectionOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.IDictionaryOfStringTValueConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.IEnumerableOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.IEnumerableWithAddMethodConverter`1")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.IListConverter`1")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.IListOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ImmutableDictionaryOfStringTValueConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ImmutableEnumerableOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.IReadOnlyDictionaryOfStringTValueConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ISetOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ListOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.QueueOfTConverter`2")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.StackOfTConverter`2")]
+ [DynamicDependency("#ctor", typeof(ArrayConverter<,>))]
+ [DynamicDependency("#ctor", typeof(ConcurrentQueueOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(ConcurrentStackOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(DictionaryOfStringTValueConverter<,>))]
+ [DynamicDependency("#ctor", typeof(ICollectionOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(IDictionaryOfStringTValueConverter<,>))]
+ [DynamicDependency("#ctor", typeof(IEnumerableOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(IEnumerableWithAddMethodConverter<>))]
+ [DynamicDependency("#ctor", typeof(IListConverter<>))]
+ [DynamicDependency("#ctor", typeof(IListOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(ImmutableDictionaryOfStringTValueConverter<,>))]
+ [DynamicDependency("#ctor", typeof(ImmutableEnumerableOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(IReadOnlyDictionaryOfStringTValueConverter<,>))]
+ [DynamicDependency("#ctor", typeof(ISetOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(ListOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(QueueOfTConverter<,>))]
+ [DynamicDependency("#ctor", typeof(StackOfTConverter<,>))]
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
Type converterType = null!;
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs
index 813969989e32f9..f28b04f3a19350 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverterFactory.cs
@@ -5,7 +5,7 @@
using System.Collections;
using System.Diagnostics;
using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
namespace System.Text.Json.Serialization.Converters
{
@@ -22,9 +22,9 @@ public override bool CanConvert(Type typeToConvert)
return true;
}
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.LargeObjectWithParameterizedConstructorConverter`1")]
- [PreserveDependency(".ctor", "System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5")]
+ [DynamicDependency("#ctor", typeof(ObjectDefaultConverter<>))]
+ [DynamicDependency("#ctor", typeof(LargeObjectWithParameterizedConstructorConverter<>))]
+ [DynamicDependency("#ctor", typeof(SmallObjectWithParameterizedConstructorConverter<,,,,>))]
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
JsonConverter converter;
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs
index 9faa76caec7371..49abb0e2cb6d04 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverterFactory.cs
@@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
namespace System.Text.Json.Serialization.Converters
{
@@ -18,9 +18,9 @@ public override bool CanConvert(Type type)
return type.IsEnum;
}
- [PreserveDependency(
- ".ctor(System.Text.Json.Serialization.Converters.EnumConverterOptions, System.Text.Json.JsonSerializerOptions)",
- "System.Text.Json.Serialization.Converters.EnumConverter`1")]
+ [DynamicDependency(
+ "#ctor(System.Text.Json.Serialization.Converters.EnumConverterOptions,System.Text.Json.JsonSerializerOptions)",
+ typeof(EnumConverter<>))]
public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options)
{
JsonConverter converter = (JsonConverter)Activator.CreateInstance(
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/KeyValuePairConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/KeyValuePairConverterFactory.cs
index 2ba7c5ffffb5f1..82b61b494e3689 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/KeyValuePairConverterFactory.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/KeyValuePairConverterFactory.cs
@@ -4,8 +4,8 @@
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
-using System.Runtime.CompilerServices;
namespace System.Text.Json.Serialization.Converters
{
@@ -20,7 +20,7 @@ public override bool CanConvert(Type typeToConvert)
return (generic == typeof(KeyValuePair<,>));
}
- [PreserveDependency(".ctor()", "System.Text.Json.Serialization.Converters.KeyValuePairConverter`2")]
+ [DynamicDependency("#ctor()", typeof(KeyValuePairConverter<,>))]
public override JsonConverter CreateConverter(Type type, JsonSerializerOptions options)
{
Debug.Assert(CanConvert(type));
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs
index a5def112ae9485..fa9e10bfd7a65b 100644
--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs
+++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonStringEnumConverter.cs
@@ -2,8 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Text.Json.Serialization.Converters;
namespace System.Text.Json.Serialization
@@ -54,9 +54,9 @@ public override bool CanConvert(Type typeToConvert)
}
///
- [PreserveDependency(
- ".ctor(System.Text.Json.Serialization.Converters.EnumConverterOptions, System.Text.Json.JsonNamingPolicy, System.Text.Json.JsonSerializerOptions)",
- "System.Text.Json.Serialization.Converters.EnumConverter`1")]
+ [DynamicDependency(
+ "#ctor(System.Text.Json.Serialization.Converters.EnumConverterOptions,System.Text.Json.JsonNamingPolicy,System.Text.Json.JsonSerializerOptions)",
+ typeof(EnumConverter<>))]
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
JsonConverter converter = (JsonConverter)Activator.CreateInstance(
diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
index 76c1e4e8b529cc..575d79f49c7a44 100644
--- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
+++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
@@ -23,6 +23,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -305,9 +306,9 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, bool
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- [PreserveDependency(".ctor(System.Reflection.ConstructorInfo,System.Reflection.Assembly,System.IntPtr,System.UInt32)", "System.Reflection.CustomAttributeData")]
- [PreserveDependency(".ctor(System.Reflection.MemberInfo,System.Object)", "System.Reflection.CustomAttributeNamedArgument")]
- [PreserveDependency(".ctor(System.Type,System.Object)", "System.Reflection.CustomAttributeTypedArgument")]
+ [DynamicDependency("#ctor(System.Reflection.ConstructorInfo,System.Reflection.Assembly,System.IntPtr,System.UInt32)", typeof(CustomAttributeData))]
+ [DynamicDependency("#ctor(System.Reflection.MemberInfo,System.Object)", typeof(CustomAttributeNamedArgument))]
+ [DynamicDependency("#ctor(System.Type,System.Object)", typeof(CustomAttributeTypedArgument))]
private static extern CustomAttributeData[] GetCustomAttributesDataInternal(ICustomAttributeProvider obj);
internal static IList GetCustomAttributesData(ICustomAttributeProvider obj, bool inherit = false)
diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs
index 3b08d67ad4f3b3..cdde58977088c3 100644
--- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs
+++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs
@@ -35,6 +35,7 @@
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace System.Reflection.Emit
@@ -217,12 +218,12 @@ public sealed class AssemblyBuilder : Assembly
private bool manifest_module_used;
[MethodImplAttribute(MethodImplOptions.InternalCall)]
+ [DynamicDependency("RuntimeResolve", typeof(ModuleBuilder))]
private static extern void basic_init(AssemblyBuilder ab);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void UpdateNativeCustomAttributes(AssemblyBuilder ab);
- [PreserveDependency("RuntimeResolve", "System.Reflection.Emit.ModuleBuilder")]
internal AssemblyBuilder(AssemblyName n, string? directory, AssemblyBuilderAccess access, bool corlib_internal)
{
aname = (AssemblyName)n.Clone();
diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
index 706867051094fa..4479c30a0ec4f8 100644
--- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
+++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
@@ -30,6 +30,7 @@
using System.Reflection.Emit;
using System.Text;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using InteropServicesCallingConvention = System.Runtime.InteropServices.CallingConvention;
namespace System.Reflection
@@ -212,7 +213,7 @@ internal static MethodBase GetMethodFromHandleNoGenericCheck(RuntimeMethodHandle
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- [PreserveDependency(".ctor(System.Reflection.ExceptionHandlingClause[],System.Reflection.LocalVariableInfo[],System.Byte[],System.Boolean,System.Int32,System.Int32)", "System.Reflection.RuntimeMethodBody")]
+ [DynamicDependency("#ctor(System.Reflection.ExceptionHandlingClause[],System.Reflection.LocalVariableInfo[],System.Byte[],System.Boolean,System.Int32,System.Int32)", typeof(RuntimeMethodBody))]
internal static extern MethodBody GetMethodBodyInternal(IntPtr handle);
internal static MethodBody GetMethodBody(IntPtr handle)
diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs
index 90a36a0230f5cc..1b5592444e54d4 100644
--- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs
+++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs
@@ -254,7 +254,7 @@ internal static bool IsSubclassOf(RuntimeType childType, RuntimeType baseType)
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool is_subclass_of(IntPtr childType, IntPtr baseType);
- [PreserveDependency(".ctor()", "System.Runtime.CompilerServices.IsByRefLikeAttribute")]
+ [DynamicDependency("#ctor()", typeof(IsByRefLikeAttribute))]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool IsByRefLike(RuntimeType type);
diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs
index fe565371b0f192..2717f3039738b3 100644
--- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs
+++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs
@@ -365,7 +365,7 @@ private static void SpinWait_nop()
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern Thread CreateInternal();
- [PreserveDependency(nameof(StartCallback))]
+ [DynamicDependency(nameof(StartCallback))]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void StartInternal(Thread runtime_thread);