Skip to content

Microsoft.XmlSerializer.Generator hangs #98447

@wegylexy

Description

@wegylexy

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions