UTC DateTime Serialization Exception

Posts   
 
    
Srikar
User
Posts: 4
Joined: 12-Feb-2009
# Posted on: 16-Jun-2009 22:59:27   

We are using LLBLGEN Pro 2.0, Adapter Model and WCF for communication.

We have to set few Entity DateTime Fields to UTC kind ( these are defined as DATE columns in Oracle DB) either during loading the Entity if possible. If not set them UTC kind before sending them to Client.

Before sending the Entity to the Client side, I had set the StatusDate of the Entity as follows.

DateTime statusDateUTC = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);

//UwApplEntity.StatusDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);

UwApplEntity.StatusDate = DateTime.Now; UwApplEntity.StatusDate = statusDateUTC; UwApplEntity.IsDirty = false;

I had received the following message from Managed Debugging Assistants. And the DateTimeKind is lost at the client side.

DateTimeInvalidLocalFormat Was Detected

A UTC DateTime is being converted to text in a format that is only correct for local times. This can happen when calling DateTime.ToString using the 'z' format specifier, which will include a local time zone offset in the output. In that case, either use the 'Z' format specifier, which designates a UTC time, or use the 'o' format string, which is the recommended way to persist a DateTime in text. This can also occur when passing a DateTime to be serialized by XmlConvert or DataSet. If using XmlConvert.ToString, pass in XmlDateTimeSerializationMode.RoundtripKind to serialize correctly. If using DataSet, set the DateTimeMode on the DataColumn object to DataSetDateTime.Utc.

How can I have the DateTime Serialized at the client side with out loosing the UTC kind?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Jun-2009 05:51:10   

Please check this: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=11517 and this manual section.

Also please post more information: exception stack trace, exact runtime library version and some relevant code we can use to figure this out. (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7725)

David Elizondo | LLBLGen Support Team
Srikar
User
Posts: 4
Joined: 12-Feb-2009
# Posted on: 17-Jun-2009 18:32:09   

LLBLGen Pro. Version: 2.0.0.0 Final(June 15th, 2007)

Adapter Model With WCF.

I don't get any runtime exception. But the problem is the DateTime is not getting serialized in UTC format.

Here's how to reproduce the issue.

UwApplEntity.StatusDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); String outXml = string.Empty; UwApplEntity.WriteXml(XmlFormatAspect.DatesInXmlDataType, out outXml);

*****Generated XML outXml ********* <StatusDate> <CurrentValue>2009-06-17T11:13:25.6221342-05:00</CurrentValue>



</StatusDate>


Please pay attention to the Date format in serialized XML, Its not in the UTC format. So when the client deserializes this xml the DateTimeKind.Utc is lost on the StatusDate Field.

I think the the serialized date should look like <CurrentValue>2009-06-17T11:13:25.6221342Z</CurrentValue> for the client to recognize it as UTC.

Any solutions to fix this issue.?

Thanks, Srikar

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 18-Jun-2009 10:54:03   

Just to make sure this isn't it. Would you please use the latest available release for v.2.0

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 18-Jun-2009 13:15:54   

You're strongly advices to upgrade to v2.6, which is a free upgrade for you. V2.6 has many advantages in the XML serialization area (like much more compact data) as well as several bugfixes which required breaking changes so it's not possible to fix this for v2.0. You can download v2.6 by logging into the customer area.

Frans Bouma | Lead developer LLBLGen Pro