Skip to content

Commit

Permalink
Last set of ILLink annotations related to System.Data.Common (#55507)
Browse files Browse the repository at this point in the history
* Last set of ILLink annotations related to System.Data.Common

* apply feedback
  • Loading branch information
krwq authored Jul 13, 2021
1 parent 2d596ec commit fe44d58
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 53 deletions.
2 changes: 2 additions & 0 deletions src/libraries/System.Data.Common/ref/System.Data.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ public void EndLoadData() { }
public System.Data.DataRow[] GetErrors() { throw null; }
public virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
protected virtual System.Type GetRowType() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Members from serialized types may be trimmed if not referenced directly.")]
protected virtual System.Xml.Schema.XmlSchema? GetSchema() { throw null; }
public void ImportRow(System.Data.DataRow? row) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Members from types used in the expression column to be trimmed if not referenced directly.")]
Expand Down Expand Up @@ -796,6 +797,7 @@ public void ReadXmlSchema(System.IO.TextReader? reader) { }
public void ReadXmlSchema(string fileName) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Members from serialized types may be trimmed if not referenced directly.")]
public void ReadXmlSchema(System.Xml.XmlReader? reader) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Members from serialized types may be trimmed if not referenced directly.")]
protected virtual void ReadXmlSerializable(System.Xml.XmlReader? reader) { }
public void RejectChanges() { }
public virtual void Reset() { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<linker>
<assembly fullname="System.Data.Common, PublicKeyToken=b03f5f7f11d50a3a">
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)</property>
<property name="Justification">DataSet.ReadXml is not trimming safe but developers cannot use it directly and have to go through the IXmlSerializable interface. Neither marking the interface nor constructors of DataSet as unsafe is a good solution so we rely on the fact that this method will be trimmed and warning will be shown only when both interface and DataSet is used in the same app which will reduce chance of seeing false positive warning.</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)</property>
<property name="Justification">DataSet.WriteXml is not trimming safe but developers cannot use it directly and have to go through the IXmlSerializable interface. Neither marking the interface nor constructors of DataSet as unsafe is a good solution so we rely on the fact that this method will be trimmed and warning will be shown only when both interface and DataSet is used in the same app which will reduce chance of seeing false positive warning.</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema()</property>
<property name="Justification">DataSet.GetSchema is not trimming safe when used in derived types but developers cannot use it directly and have to go through the IXmlSerializable interface. Neither marking the interface nor constructors of DataSet as unsafe is a good solution so we rely on the fact that this method will be trimmed and warning will be shown only when both interface and DataSet is used in the same app which will reduce chance of seeing false positive warning.</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)</property>
<property name="Justification">DataTable.ReadXml is not trimming safe but developers cannot use it directly and have to go through the IXmlSerializable interface. Neither marking the interface nor constructors of DataTable as unsafe is a good solution so we rely on the fact that this method will be trimmed and warning will be shown only when both interface and DataTable is used in the same app which will reduce chance of seeing false positive warning.</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)</property>
<property name="Justification">DataTable.WriteXml is not trimming safe but developers cannot use it directly and have to go through the IXmlSerializable interface. Neither marking the interface nor constructors of DataTable as unsafe is a good solution so we rely on the fact that this method will be trimmed and warning will be shown only when both interface and DataTable is used in the same app which will reduce chance of seeing false positive warning.</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.GetSchema()</property>
<property name="Justification">DataTable.GetSchema is not trimming safe when used in derived types but developers cannot use it directly and have to go through the IXmlSerializable interface. Neither marking the interface nor constructors of DataTable as unsafe is a good solution so we rely on the fact that this method will be trimmed and warning will be shown only when both interface and DataTable is used in the same app which will reduce chance of seeing false positive warning.</property>
</attribute>
</assembly>
</linker>

This file was deleted.

24 changes: 20 additions & 4 deletions src/libraries/System.Data.Common/src/System/Data/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3444,7 +3444,6 @@ public static XmlSchemaComplexType GetDataSetSchema(XmlSchemaSet? schemaSet)

private static bool PublishLegacyWSDL() => false;

#pragma warning disable 8632
XmlSchema? IXmlSerializable.GetSchema()
{
if (GetType() == typeof(DataSet))
Expand All @@ -3457,12 +3456,18 @@ public static XmlSchemaComplexType GetDataSetSchema(XmlSchemaSet? schemaSet)
XmlWriter writer = new XmlTextWriter(stream, null);
if (writer != null)
{
(new XmlTreeGen(SchemaFormat.WebService)).Save(this, writer);
WriteXmlSchema(this, writer);
}
stream.Position = 0;
return XmlSchema.Read(new XmlTextReader(stream), null);
}

[RequiresUnreferencedCode("DataSet.GetSchema uses TypeDescriptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly.")]
private static void WriteXmlSchema(DataSet ds, XmlWriter writer)
{
(new XmlTreeGen(SchemaFormat.WebService)).Save(ds, writer);
}

void IXmlSerializable.ReadXml(XmlReader reader)
{
bool fNormalization = true;
Expand All @@ -3483,7 +3488,7 @@ void IXmlSerializable.ReadXml(XmlReader reader)
}
}

ReadXmlSerializable(reader);
ReadXmlSerializableInternal(reader);

if (xmlTextParser != null)
{
Expand All @@ -3495,12 +3500,23 @@ void IXmlSerializable.ReadXml(XmlReader reader)
}
}

[RequiresUnreferencedCode("DataSet.ReadXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.")]
private void ReadXmlSerializableInternal(XmlReader reader)
{
ReadXmlSerializable(reader);
}

void IXmlSerializable.WriteXml(XmlWriter writer)
{
WriteXmlInternal(writer);
}

[RequiresUnreferencedCode("DataSet.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.")]
private void WriteXmlInternal(XmlWriter writer)
{
WriteXmlSchema(writer, SchemaFormat.WebService, null);
WriteXml(writer, XmlWriteMode.DiffGram);
}
#pragma warning restore 8632

[RequiresUnreferencedCode("Using LoadOption may cause members from types used in the expression column to be trimmed if not referenced directly.")]
public virtual void Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler? errorHandler, params DataTable[] tables)
Expand Down
30 changes: 22 additions & 8 deletions src/libraries/System.Data.Common/src/System/Data/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5955,6 +5955,7 @@ internal XmlReadMode ReadXml(XmlReader? reader, bool denyResolving)
}
}

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
internal XmlReadMode ReadXml(XmlReader? reader, XmlReadMode mode, bool denyResolving)
{
IDisposable? restrictedScope = null;
Expand Down Expand Up @@ -6685,8 +6686,11 @@ public static XmlSchemaComplexType GetDataTableSchema(XmlSchemaSet? schemaSet)
return type;
}

XmlSchema? IXmlSerializable.GetSchema() => GetSchema();
XmlSchema? IXmlSerializable.GetSchema() => GetXmlSchema();

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046:UnrecognizedReflectionPattern",
Justification = "https://github.com/mono/linker/issues/1187 Trimmer thinks this implements IXmlSerializable.GetSchema() and warns about not matching attributes.")]
protected virtual XmlSchema? GetSchema()
{
if (GetType() == typeof(DataTable))
Expand All @@ -6704,7 +6708,12 @@ public static XmlSchemaComplexType GetDataTableSchema(XmlSchemaSet? schemaSet)
return XmlSchema.Read(new XmlTextReader(stream), null);
}

#pragma warning disable 8632
[RequiresUnreferencedCode("DataTable.GetSchema uses TypeDescriptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly.")]
private XmlSchema? GetXmlSchema()
{
return GetSchema();
}

void IXmlSerializable.ReadXml(XmlReader reader)
{
IXmlTextParser? textReader = reader as IXmlTextParser;
Expand All @@ -6714,28 +6723,33 @@ void IXmlSerializable.ReadXml(XmlReader reader)
fNormalization = textReader.Normalized;
textReader.Normalized = false;
}
ReadXmlSerializable(reader);
ReadXmlSerializableInternal(reader);

if (textReader != null)
{
textReader.Normalized = fNormalization;
}
}

[RequiresUnreferencedCode("DataTable.ReadXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.")]
private void ReadXmlSerializableInternal(XmlReader reader)
{
ReadXmlSerializable(reader);
}

void IXmlSerializable.WriteXml(XmlWriter writer)
{
WriteXmlCore(writer);
WriteXmlInternal(writer);
}
#pragma warning restore 8632

// This method exists so that suppression can be placed on `IXmlSerializable.WriteXml(XmlWriter writer)`
private void WriteXmlCore(XmlWriter writer)
[RequiresUnreferencedCode("DataTable.WriteXml uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly.")]
private void WriteXmlInternal(XmlWriter writer)
{
WriteXmlSchema(writer, false);
WriteXml(writer, XmlWriteMode.DiffGram, false);
}
#pragma warning restore 8632

[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
protected virtual void ReadXmlSerializable(XmlReader? reader) => ReadXml(reader, XmlReadMode.DiffGram, true);

// RowDiffIdUsageSection & DSRowDiffIdUsageSection Usage:
Expand Down

0 comments on commit fe44d58

Please sign in to comment.