diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index 38a37217d2fa6..7bcd618b806d2 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -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.")] @@ -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() { } diff --git a/src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.LibraryBuild.xml b/src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.LibraryBuild.xml new file mode 100644 index 0000000000000..fff5aa12ed91c --- /dev/null +++ b/src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.LibraryBuild.xml @@ -0,0 +1,47 @@ + + + + + ILLink + IL2026 + member + M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader) + 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. + + + ILLink + IL2026 + member + M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter) + 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. + + + ILLink + IL2026 + member + M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema() + 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. + + + ILLink + IL2026 + member + M:System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader) + 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. + + + ILLink + IL2026 + member + M:System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter) + 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. + + + ILLink + IL2026 + member + M:System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.GetSchema() + 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. + + + diff --git a/src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.xml b/src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.xml deleted file mode 100644 index 393abfc15c492..0000000000000 --- a/src/libraries/System.Data.Common/src/ILLink/ILLink.Suppressions.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - ILLink - IL2026 - member - M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema() - - - ILLink - IL2026 - member - M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader) - - - ILLink - IL2026 - member - M:System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter) - - - ILLink - IL2026 - member - M:System.Data.DataTable.GetSchema() - - - ILLink - IL2026 - member - M:System.Data.DataTable.ReadXml(System.Xml.XmlReader,System.Data.XmlReadMode,System.Boolean) - - - ILLink - IL2026 - member - M:System.Data.DataTable.WriteXmlCore(System.Xml.XmlWriter) - - - diff --git a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs index 33c265766cee4..6974aafce602c 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs @@ -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)) @@ -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; @@ -3483,7 +3488,7 @@ void IXmlSerializable.ReadXml(XmlReader reader) } } - ReadXmlSerializable(reader); + ReadXmlSerializableInternal(reader); if (xmlTextParser != null) { @@ -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) diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs index bd8257122e233..22ace6fce6404 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs @@ -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; @@ -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)) @@ -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; @@ -6714,7 +6723,7 @@ void IXmlSerializable.ReadXml(XmlReader reader) fNormalization = textReader.Normalized; textReader.Normalized = false; } - ReadXmlSerializable(reader); + ReadXmlSerializableInternal(reader); if (textReader != null) { @@ -6722,20 +6731,25 @@ void IXmlSerializable.ReadXml(XmlReader reader) } } + [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: