Skip to content

Commit

Permalink
XmlSerializer support for IsDynamicCodeSupported=false
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eerhardt authored and github-actions committed Sep 23, 2021
1 parent 6e8f538 commit fd5a47d
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,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;
}

Expand All @@ -218,6 +221,12 @@ public XmlSerializer(Type type, string? defaultNamespace)
_primitiveType = type;
return;
}

if (Mode == SerializationMode.ReflectionOnly)
{
return;
}

_tempAssembly = s_cache[defaultNamespace, type];
if (_tempAssembly == null)
{
Expand Down Expand Up @@ -270,7 +279,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);
}
}

[RequiresUnreferencedCode("calls ImportTypeMapping")]
Expand Down

0 comments on commit fd5a47d

Please sign in to comment.