Microsoft.XmlSerializer.Generator hangs
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- build-system, devtools
Research direction
Start by building the simple library project with Microsoft.XmlSerializer.Generator enabled, using the provided MeasureListType reproduction and its XML text surrogate. Compare behavior with the generator disabled and vary the number of surrogate properties or IXmlSerializable implementations. Done means compilation no longer hangs and the generated serializer does not throw at runtime when the concerned properties are absent from the raw XML.
Written by the indexing model from the issue text.
Description
Description
First of all, the classes generated for https://aixm.aero/document/aixm-51-xml-schema-xsd are not fully supported. For example, array of doubles in XML text content, e.g. <doubleList>123.45 678.9 12.3 4.5</doubleList>.
[XmlText]
public double[] Text { get; set; }
The above throws an InvalidOperationException at runtime. So I use a surrogate as follow.
[XmlText]
+[JsonIgnore]
+public string TextAsString {
+ get => string.Join(' ', Text.Select(d => d.ToString()));
+ set => Text = value.Split(' ').Select(double.Parse).ToArray();
+}
+[XmlIgnore]
public double[] Text { get; set; }
(It works without using the source generator.)
Then, Microsoft.XmlSerializer.Generator hangs at compile-time when I apply this workaround to more than 2 such properties. It also hangs if I implement IXmlSerializable on the classes instead of applying the surrogates. The CPU fan keeps spinning, so it is not a dead lock, but potential infinite loop?
Ideally, it should support deserializing numeric arrays encoded in XML text content.
Reproduction Steps
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.8.3928.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.opengis.net/gml/3.2")]
[System.Xml.Serialization.XmlRootAttribute("valueList", Namespace="http://www.opengis.net/gml/3.2", IsNullable=false)]
public partial class MeasureListType {
private string uomField;
private double[] textField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string uom {
get {
return this.uomField;
}
set {
this.uomField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
[JsonIgnore]
public string TextAsString
{
get => string.Join(' ', Text);
set => Text = value.Split(' ').Select(s => double.Parse(s)).ToArray();
}
[XmlIgnore]
public double[] Text {
get {
return this.textField;
}
set {
this.textField = value;
}
}
}
Build a simple library project with the tool enabled.
Expected behavior
It should generate a serializer that at least won't throw during run-time when the properties concerned do not appear in the raw XML.
Actual behavior
The source generator hangs during compile-time.
Regression?
No response
Known Workarounds
Disable the XML serializer generator tool.
Configuration
- .NET 8
- Windows 11 22631.3085
- x64
- not specific to the configuration
- not specific to any browser
Other information
No response
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 589
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
bug documentation frontend
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
azurenoops/spin_agent#975 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100