New XmlSerializer with DefaultValue(0.0) and "Decimal" field/property - by Jochen Kalmbach

Status : 

 


2
0
Sign in
to vote
ID 1050801 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 12/9/2014 12:09:44 PM
Access Restriction Public

Description

If a public field (or property) has the datatype "decimal" and a "DefaultValue(0.0)" (which is a "double"), then the serializer will throw an "InvalidProgramException" during serialization!

Here is a small repo-code:

using System.ComponentModel;
using System.IO;
using System.Xml.Serialization;

namespace ConsoleApplication1
{
  public class Program
  {
    static void Main()
    {
      new XmlSerializer(typeof (Program)).Serialize(new StringWriter(), new Program());
    }

    [DefaultValue(0.0)]
    public decimal Value;
  }
}
Sign in to post a comment.
Posted by Microsoft on 9/22/2016 at 4:57 PM
Thanks for reporting this issue. There're several work around for this issue.
1. Use 0 instead of 0.0 as the default value.
2. Use the old serialization generator (add useLegacySerializerGeneration="true" to the config)
3. Use double instead of decimal here.

Thanks!
Huangli
Posted by Microsoft on 12/9/2014 at 1:10 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If you require immediate assistance with this issue, please contact product support at http://support.microsoft.com/ph/1117.