开发者

Why the result of serialization of a class is different on different machine?

I have a class Header which looks like

/// <remarks />
[GeneratedCode("xsd", "4.0.30319.1")]
[Serializable]
[DebuggerStepThrough]
[DesignerCategory("code")]
[XmlType(Namespace = "http://www.schemas.com/IntegrationApplication-instance")]
[XmlRoot(Namespace = "http://www.schemas.com/IntegrationApplication-instance", IsNullable = true)]
public class Header
{
    private string operationField;

    开发者_如何转开发private string requestIdField;

    private DateTime sendDateField;

    private string senderSystemNameField;

    /// <remarks />
    [XmlElement(IsNullable = true)]
    public string Operation
    {
        get
        {
            return operationField;
        }
        set
        {
            operationField = value;
        }
    }

    /// <remarks />
    public string RequestId
    {
        get
        {
            return requestIdField;
        }
        set
        {
            requestIdField = value;
        }
    }

    /// <remarks />
    public DateTime SendDate
    {
        get
        {
            return sendDateField;
        }
        set
        {
            sendDateField = value;
        }
    }

    /// <remarks />
    [XmlElement(IsNullable = true)]
    public string SenderSystemName
    {
        get
        {
            return senderSystemNameField;
        }
        set
        {
            senderSystemNameField = value;
        }
    }
}

When I serialize it on my machine, SendDate is specified, but for my surprise when I run serialization code on another machine SendDate is somehow missed. The piece of code I use is:

var header = new Header()
            {
                Operation = "new ope",
                RequestId = "",
                SendDate = DateTime.Now,
                SenderSystemName = "asd"
            };
var serializer = new XmlSerializer(typeof (Header));
var sb = new StringBuilder();
serializer.Serialize(new StringWriter(sb, CultureInfo.InvariantCulture), header);

Why the results of this code is different on different machines?


I thing it is a culture issue. I don't see the deserialization code but it could be that this code expect the date to be in a different format. If this code does not specify culture, the regional settings of the machine on wich the code runs will be taken. Check that the regional settings of both machines are the same, specially date format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜