Skip to content

Commit 8f9edb3

Browse files
authored
Resolve ILLink warnings in System.Runtime.Serialization.Formatters (#46964)
* Resolve ILLink warnings in System.Runtime.Serialization.Formatters Contributes to #45623
1 parent 81a1321 commit 8f9edb3

File tree

19 files changed

+262
-109
lines changed

19 files changed

+262
-109
lines changed

src/libraries/System.ComponentModel.TypeConverter/src/ILLink/ILLink.Suppressions.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,17 @@
289289
<property name="Scope">member</property>
290290
<property name="Target">M:System.ComponentModel.BindingList`1.get_ItemTypeHasDefaultConstructor</property>
291291
</attribute>
292+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
293+
<argument>ILLink</argument>
294+
<argument>IL2026</argument>
295+
<property name="Scope">member</property>
296+
<property name="Target">M:System.ComponentModel.Design.DesigntimeLicenseContextSerializer.Deserialize(System.IO.Stream,System.String,System.ComponentModel.Design.RuntimeLicenseContext)</property>
297+
</attribute>
298+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
299+
<argument>ILLink</argument>
300+
<argument>IL2026</argument>
301+
<property name="Scope">member</property>
302+
<property name="Target">M:System.ComponentModel.Design.DesigntimeLicenseContextSerializer.Serialize(System.IO.Stream,System.String,System.ComponentModel.Design.DesigntimeLicenseContext)</property>
303+
</attribute>
292304
</assembly>
293305
</linker>

src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,17 @@
133133
<property name="Scope">member</property>
134134
<property name="Target">M:System.Data.DataColumn.get_DefaultValue</property>
135135
</attribute>
136+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
137+
<argument>ILLink</argument>
138+
<argument>IL2026</argument>
139+
<property name="Scope">member</property>
140+
<property name="Target">M:System.Data.DataSet.DeserializeDataSetSchema(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext,System.Data.SerializationFormat,System.Data.SchemaSerializationMode)</property>
141+
</attribute>
142+
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
143+
<argument>ILLink</argument>
144+
<argument>IL2026</argument>
145+
<property name="Scope">member</property>
146+
<property name="Target">M:System.Data.DataSet.SerializeDataSet(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext,System.Data.SerializationFormat)</property>
147+
</attribute>
136148
</assembly>
137-
</linker>
149+
</linker>

src/libraries/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ protected Formatter() { }
1616
public abstract System.Runtime.Serialization.StreamingContext Context { get; set; }
1717
public abstract System.Runtime.Serialization.ISurrogateSelector? SurrogateSelector { get; set; }
1818
[System.ObsoleteAttribute("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
19+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
1920
public abstract object Deserialize(System.IO.Stream serializationStream);
2021
protected virtual object? GetNext(out long objID) { throw null; }
2122
protected virtual long Schedule(object? obj) { throw null; }
2223
[System.ObsoleteAttribute("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
24+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
2325
public abstract void Serialize(System.IO.Stream serializationStream, object graph);
2426
protected abstract void WriteArray(object obj, string name, System.Type memberType);
2527
protected abstract void WriteBoolean(bool val, string name);
@@ -74,12 +76,13 @@ public static partial class FormatterServices
7476
{
7577
public static void CheckTypeSecurity(System.Type t, System.Runtime.Serialization.Formatters.TypeFilterLevel securityLevel) { }
7678
public static object?[] GetObjectData(object obj, System.Reflection.MemberInfo[] members) { throw null; }
77-
public static object GetSafeUninitializedObject(System.Type type) { throw null; }
78-
public static System.Reflection.MemberInfo[] GetSerializableMembers(System.Type type) { throw null; }
79-
public static System.Reflection.MemberInfo[] GetSerializableMembers(System.Type type, System.Runtime.Serialization.StreamingContext context) { throw null; }
79+
public static object GetSafeUninitializedObject([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type) { throw null; }
80+
public static System.Reflection.MemberInfo[] GetSerializableMembers([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type) { throw null; }
81+
public static System.Reflection.MemberInfo[] GetSerializableMembers([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, System.Runtime.Serialization.StreamingContext context) { throw null; }
8082
public static System.Runtime.Serialization.ISerializationSurrogate GetSurrogateForCyclicalReference(System.Runtime.Serialization.ISerializationSurrogate innerSurrogate) { throw null; }
83+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Types might be removed")]
8184
public static System.Type? GetTypeFromAssembly(System.Reflection.Assembly assem, string name) { throw null; }
82-
public static object GetUninitializedObject(System.Type type) { throw null; }
85+
public static object GetUninitializedObject([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type) { throw null; }
8386
public static object PopulateObjectMembers(object obj, System.Reflection.MemberInfo[] members, object?[] data) { throw null; }
8487
}
8588
public partial interface IFormatter
@@ -88,8 +91,10 @@ public partial interface IFormatter
8891
System.Runtime.Serialization.StreamingContext Context { get; set; }
8992
System.Runtime.Serialization.ISurrogateSelector? SurrogateSelector { get; set; }
9093
[System.ObsoleteAttribute("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
94+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
9195
object Deserialize(System.IO.Stream serializationStream);
9296
[System.ObsoleteAttribute("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
97+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
9398
void Serialize(System.IO.Stream serializationStream, object graph);
9499
}
95100
public partial interface ISerializationSurrogate
@@ -112,17 +117,23 @@ public ObjectIDGenerator() { }
112117
public partial class ObjectManager
113118
{
114119
public ObjectManager(System.Runtime.Serialization.ISurrogateSelector? selector, System.Runtime.Serialization.StreamingContext context) { }
120+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("ObjectManager is not trim compatible because the Type of objects being managed cannot be statically discovered.")]
115121
public virtual void DoFixups() { }
116122
public virtual object? GetObject(long objectID) { throw null; }
117123
public virtual void RaiseDeserializationEvent() { }
124+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("ObjectManager is not trim compatible because the Type of objects being managed cannot be statically discovered.")]
118125
public void RaiseOnDeserializingEvent(object obj) { }
119126
public virtual void RecordArrayElementFixup(long arrayToBeFixed, int index, long objectRequired) { }
120127
public virtual void RecordArrayElementFixup(long arrayToBeFixed, int[] indices, long objectRequired) { }
121128
public virtual void RecordDelayedFixup(long objectToBeFixed, string memberName, long objectRequired) { }
122129
public virtual void RecordFixup(long objectToBeFixed, System.Reflection.MemberInfo member, long objectRequired) { }
130+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("ObjectManager is not trim compatible because the Type of objects being managed cannot be statically discovered.")]
123131
public virtual void RegisterObject(object obj, long objectID) { }
132+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("ObjectManager is not trim compatible because the Type of objects being managed cannot be statically discovered.")]
124133
public void RegisterObject(object obj, long objectID, System.Runtime.Serialization.SerializationInfo info) { }
134+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("ObjectManager is not trim compatible because the Type of objects being managed cannot be statically discovered.")]
125135
public void RegisterObject(object obj, long objectID, System.Runtime.Serialization.SerializationInfo? info, long idOfContainingObj, System.Reflection.MemberInfo? member) { }
136+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("ObjectManager is not trim compatible because the Type of objects being managed cannot be statically discovered.")]
126137
public void RegisterObject(object obj, long objectID, System.Runtime.Serialization.SerializationInfo? info, long idOfContainingObj, System.Reflection.MemberInfo? member, int[]? arrayIndex) { }
127138
}
128139
public abstract partial class SerializationBinder
@@ -135,6 +146,7 @@ public sealed partial class SerializationObjectManager
135146
{
136147
public SerializationObjectManager(System.Runtime.Serialization.StreamingContext context) { }
137148
public void RaiseOnSerializedEvent() { }
149+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("SerializationObjectManager is not trim compatible because the Type of objects being managed cannot be statically discovered.")]
138150
public void RegisterObject(object obj) { }
139151
}
140152
public partial class SurrogateSelector : System.Runtime.Serialization.ISurrogateSelector
@@ -184,8 +196,10 @@ public BinaryFormatter(System.Runtime.Serialization.ISurrogateSelector? selector
184196
public System.Runtime.Serialization.ISurrogateSelector? SurrogateSelector { get { throw null; } set { } }
185197
public System.Runtime.Serialization.Formatters.FormatterTypeStyle TypeFormat { get { throw null; } set { } }
186198
[System.ObsoleteAttribute("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
199+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
187200
public object Deserialize(System.IO.Stream serializationStream) { throw null; }
188201
[System.ObsoleteAttribute("BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information.", DiagnosticId = "SYSLIB0011", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
202+
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("BinaryFormatter serialization is not trim compatible because the Type of objects being processed cannot be statically discovered.")]
189203
public void Serialize(System.IO.Stream serializationStream, object graph) { }
190204
}
191205
}

src/libraries/System.Runtime.Serialization.Formatters/src/ILLink/ILLink.Suppressions.xml

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatter.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.IO;
5-
using System.Globalization;
64
using System.Collections;
7-
using System.Reflection;
5+
using System.Diagnostics.CodeAnalysis;
6+
using System.Globalization;
7+
using System.IO;
88

99
namespace System.Runtime.Serialization
1010
{
@@ -21,6 +21,7 @@ protected Formatter()
2121
}
2222

2323
[Obsolete(Obsoletions.BinaryFormatterMessage, DiagnosticId = Obsoletions.BinaryFormatterDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
24+
[RequiresUnreferencedCode(IFormatter.RequiresUnreferencedCodeMessage)]
2425
public abstract object Deserialize(Stream serializationStream);
2526

2627
protected virtual object? GetNext(out long objID)
@@ -61,6 +62,7 @@ protected virtual long Schedule(object? obj)
6162
}
6263

6364
[Obsolete(Obsoletions.BinaryFormatterMessage, DiagnosticId = Obsoletions.BinaryFormatterDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
65+
[RequiresUnreferencedCode(IFormatter.RequiresUnreferencedCodeMessage)]
6466
public abstract void Serialize(Stream serializationStream, object graph);
6567

6668
protected abstract void WriteArray(object obj, string name, Type memberType);

0 commit comments

Comments
 (0)