Skip to content

Commit fd5a47d

Browse files
eerhardtgithub-actions
authored andcommitted
XmlSerializer support for IsDynamicCodeSupported=false
Add more checks to XmlSerializer to check the SerializationMode. Don't try to use Reflection.Emit if the SerializationMode is ReflectionOnly. These changes were ported from * dotnet/runtimelab#593 * dotnet/runtimelab#600 Fix #59167
1 parent 6e8f538 commit fd5a47d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ public XmlSerializer(XmlTypeMapping xmlTypeMapping)
194194
if (xmlTypeMapping == null)
195195
throw new ArgumentNullException(nameof(xmlTypeMapping));
196196

197-
_tempAssembly = GenerateTempAssembly(xmlTypeMapping);
197+
if (Mode != SerializationMode.ReflectionOnly)
198+
{
199+
_tempAssembly = GenerateTempAssembly(xmlTypeMapping);
200+
}
198201
_mapping = xmlTypeMapping;
199202
}
200203

@@ -218,6 +221,12 @@ public XmlSerializer(Type type, string? defaultNamespace)
218221
_primitiveType = type;
219222
return;
220223
}
224+
225+
if (Mode == SerializationMode.ReflectionOnly)
226+
{
227+
return;
228+
}
229+
221230
_tempAssembly = s_cache[defaultNamespace, type];
222231
if (_tempAssembly == null)
223232
{
@@ -270,7 +279,10 @@ public XmlSerializer(Type type, XmlAttributeOverrides? overrides, Type[]? extraT
270279
DefaultNamespace = defaultNamespace;
271280
_rootType = type;
272281
_mapping = GenerateXmlTypeMapping(type, overrides, extraTypes, root, defaultNamespace);
273-
_tempAssembly = GenerateTempAssembly(_mapping, type, defaultNamespace, location);
282+
if (Mode != SerializationMode.ReflectionOnly)
283+
{
284+
_tempAssembly = GenerateTempAssembly(_mapping, type, defaultNamespace, location);
285+
}
274286
}
275287

276288
[RequiresUnreferencedCode("calls ImportTypeMapping")]

0 commit comments

Comments
 (0)