From a8adad9b98c39d084042bf82e1bd216510cadaff Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Sat, 7 Aug 2021 09:01:53 +0300 Subject: [PATCH 1/3] Add GenerateSerializer overload with defaultNamespace argument --- .../src/System/Xml/Serialization/XmlSerializer.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs index 3c36a8337fb4c..35009bfe3f644 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs @@ -632,6 +632,14 @@ private static XmlSerializer[] GetReflectionBasedSerializers(XmlMapping[] mappin [UnconditionalSuppressMessage("SingleFile", "IL3000: Avoid accessing Assembly file path when publishing as a single file", Justification = "Code is used on diagnostics so we fallback to print assembly.FullName if assembly.Location is empty")] internal static bool GenerateSerializer(Type[]? types, XmlMapping[] mappings, Stream stream) + { + return GenerateSerializer(types, mappings, null, stream); + } + + [RequiresUnreferencedCode("calls GenerateSerializerToStream")] + [UnconditionalSuppressMessage("SingleFile", "IL3000: Avoid accessing Assembly file path when publishing as a single file", + Justification = "Code is used on diagnostics so we fallback to print assembly.FullName if assembly.Location is empty")] + internal static bool GenerateSerializer(Type[]? types, XmlMapping[] mappings, string defaultNamespace, Stream stream) { if (types == null || types.Length == 0) return false; @@ -669,7 +677,7 @@ internal static bool GenerateSerializer(Type[]? types, XmlMapping[] mappings, St } } - return TempAssembly.GenerateSerializerToStream(mappings, types, null, assembly, new Hashtable(), stream); + return TempAssembly.GenerateSerializerToStream(mappings, types, defaultNamespace, assembly, new Hashtable(), stream); } [RequiresUnreferencedCode("calls Contract")] From de158be83f6e3b8a0c080eba0687aec415f4374d Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Sat, 7 Aug 2021 09:31:15 +0300 Subject: [PATCH 2/3] Update XmlSerializer.cs Add null-forgiving operator --- .../src/System/Xml/Serialization/XmlSerializer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs index 35009bfe3f644..0fbb02f7f3086 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs @@ -633,7 +633,7 @@ private static XmlSerializer[] GetReflectionBasedSerializers(XmlMapping[] mappin Justification = "Code is used on diagnostics so we fallback to print assembly.FullName if assembly.Location is empty")] internal static bool GenerateSerializer(Type[]? types, XmlMapping[] mappings, Stream stream) { - return GenerateSerializer(types, mappings, null, stream); + return GenerateSerializer(types, mappings, null!, stream); } [RequiresUnreferencedCode("calls GenerateSerializerToStream")] From b655e6d5b85b0d6c3c3c5a8a79fe9c30f990c5b2 Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Sat, 7 Aug 2021 18:46:21 +0300 Subject: [PATCH 3/3] Update XmlSerializer.cs Minor correction --- .../src/System/Xml/Serialization/XmlSerializer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs index 0fbb02f7f3086..e357e5ea41874 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs @@ -633,13 +633,13 @@ private static XmlSerializer[] GetReflectionBasedSerializers(XmlMapping[] mappin Justification = "Code is used on diagnostics so we fallback to print assembly.FullName if assembly.Location is empty")] internal static bool GenerateSerializer(Type[]? types, XmlMapping[] mappings, Stream stream) { - return GenerateSerializer(types, mappings, null!, stream); + return GenerateSerializer(types, mappings, null, stream); } [RequiresUnreferencedCode("calls GenerateSerializerToStream")] [UnconditionalSuppressMessage("SingleFile", "IL3000: Avoid accessing Assembly file path when publishing as a single file", Justification = "Code is used on diagnostics so we fallback to print assembly.FullName if assembly.Location is empty")] - internal static bool GenerateSerializer(Type[]? types, XmlMapping[] mappings, string defaultNamespace, Stream stream) + internal static bool GenerateSerializer(Type[]? types, XmlMapping[] mappings, string? defaultNamespace, Stream stream) { if (types == null || types.Length == 0) return false;