0
[Browsable(false)]
[XmlArray("CommonRows"), XmlArrayItem("Row", typeof(string))]
public List<string> CommonRows { get; set; }

I am Serializing list, after converting it getting the output in below XML format.

<CommonRows>
        <Row>3</Row>
        <Row>5</Row>
        <Row>7</Row>
        <Row>9</Row>
</CommonRows>

How to do I make Dictionary serializable.

public Dictionary<string, List<string>> CommonRows { get; set; }

I am trying to get the output in this way

<dictionary>
  <item>
    <key>
      <string>key1</string>
    </key>
    <value>
      <string>value1</string>
      <string>value1</string>
      <string>value1</string>
    </value>
  </item>
  <item>
    <key>
      <string>key1</string>
    </key>
    <value>
        <string>value2</string>
        <string>value2</string>
        <string>value2</string>
        <string>value2</string>
    </value>
  </item>
</dictionary>

Please suggest how to serialized in this way?

Atul Dislay
  • 125
  • 3
  • 12

1 Answers1

0

The XmlSerializer cannot process classes implementing the IDictionary interface. Please check this link

In MSDN documentation, there is Q and A:

Q: Why can't I serialize hashtables?

A: The XmlSerializer cannot process classes implementing the IDictionary interface. This was partly due to schedule constraints and partly due to the fact that a hashtable does not have a counterpart in the XSD type system. The only solution is to implement a custom hashtable that does not implement the IDictionary interface.

Similar question is here.

Subodh S
  • 105
  • 1
  • 4