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 b316e88b87e38..b8aa53b73b148 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 @@ -177,7 +177,10 @@ public XmlSerializer(XmlTypeMapping xmlTypeMapping) if (xmlTypeMapping == null) throw new ArgumentNullException(nameof(xmlTypeMapping)); - _tempAssembly = GenerateTempAssembly(xmlTypeMapping); + if (Mode != SerializationMode.ReflectionOnly) + { + _tempAssembly = GenerateTempAssembly(xmlTypeMapping); + } _mapping = xmlTypeMapping; } @@ -256,7 +259,10 @@ public XmlSerializer(Type type, XmlAttributeOverrides? overrides, Type[]? extraT DefaultNamespace = defaultNamespace; _rootType = type; _mapping = GenerateXmlTypeMapping(type, overrides, extraTypes, root, defaultNamespace); - _tempAssembly = GenerateTempAssembly(_mapping, type, defaultNamespace, location); + if (Mode != SerializationMode.ReflectionOnly) + { + _tempAssembly = GenerateTempAssembly(_mapping, type, defaultNamespace, location); + } } private XmlTypeMapping GenerateXmlTypeMapping(Type type, XmlAttributeOverrides? overrides, Type[]? extraTypes, XmlRootAttribute? root, string? defaultNamespace)