none
Regading workarounds the issue: XML Serialization: System.Xml.XmlSerializer Does Not Serialize Default Values RRS feed

  • Question

  • Hi,

    In the Article ID: 325691 the support suggests two methods to solve the problem:

    1. After the Xsd.exe file generates the classes from the schemas, manually comment out or remove all of the [System.ComponentModel.DefaultValueAttribute("myFieldName")] attributes from the class files.
    2. Use the class constructors instead of the schema to assign the default values.

    In the first solution(workaround), the generated class from xsd file contains already the constructor and the default values are assigned to that field or property. And commenting out or removing all  [System.ComponentModel.DefaultValueAttribute("myFieldName")] solve the problem.

    So I was wondering how the second solution works? Is the "class constructors" mentioned in the second solution refers to the classes generated from xsd?

    Any help is appreciated.

    Thanks,

    Sole

    Thursday, January 9, 2014 5:37 PM

Answers

  • Hi,

    >>So I was wondering how the second solution works? Is the "class constructors" mentioned in the second solution refers to the classes generated from xsd?

    Yes, it works. The "class constructors" mentioned in the second solution does not refers to the classes generated from xsd.

    For the details information, please try to check this article which will tell you how to implement it:
    #XmlDefaultValue:
    http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributes.xmldefaultvalue(v=vs.110).aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 10, 2014 11:13 AM
    Moderator