-
Notifications
You must be signed in to change notification settings - Fork 5.3k
XmlSerializer support for IsDynamicCodeSupported=false #59386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
9a82ac3
ccb3aa0
cdd1d14
f1b0cac
d6fb135
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
|
||
|
|
@@ -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) | ||
| { | ||
|
|
@@ -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")] | ||
|
|
@@ -534,6 +546,16 @@ public virtual bool CanDeserialize(XmlReader xmlReader) | |
| { | ||
| return _tempAssembly.CanRead(_mapping, xmlReader); | ||
| } | ||
| else if (ShouldUseReflectionBasedSerialization(_mapping) || _isReflectionBasedSerializer) | ||
|
||
| { | ||
| XmlMapping mapping = GetMapping(); | ||
| ElementAccessor element = mapping.Accessor; | ||
| string elementNamespace = element.Form == XmlSchemaForm.Qualified ? element.Namespace! : string.Empty; | ||
|
|
||
| return mapping.IsReadable && | ||
| mapping.GenerateSerializer && | ||
| xmlReader.IsStartElement(element.Name, elementNamespace); | ||
| } | ||
| else | ||
| { | ||
| return false; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, because we want to restructure this RefEmit/Reflection-Based dichotomy in 7.0... but SOAP mappings also trigger using reflection-based serialization. Perhaps consider using
if (!ShouldUseReflectionBasedSerialization(_mapping))in these three constructors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are late in 6.0, I wanted to make the least risk change that fixes the issue. The least risk (IMO) is to use what worked in UAP and in the NativeAOT branch.
This suggestion would affect SOAP in "normal" applications, not just when
IsDynamicCodeSupported=false. I can log an issue for someone to investigate taking this approach in 7.0.