function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bryan WagstaffBryan Wagstaff 

System.FormatException when calling sforce.query()

When I call the 7.0 api's query command, I get an exception.

There is an error in XML document (1, 519).
----> System.FormatException : String was not recognized as a valid DateTime.

The position number varies based on the query, but the exception flows out of sforce.query().

Any ideas on where to look?

The full exception is:

at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at GAPClientInfo.SForce.SforceService.query(String queryString) in C:\Documents and Settings\bwagstaff\My Documents\Visual Studio 2005\Projects\GAPClientInfo\GAPClientInfo\Web References\SForce\Reference.cs:line 678
at GAPClientInfo.GAPClientData.UpdateGeocodeCache(IDbConnection connection) in C:\Documents and Settings\bwagstaff\My Documents\Visual Studio 2005\Projects\GAPClientInfo\GAPClientInfo\GAPClientData.cs:line 106
at GAPClientInfo.GAPClientDataTests.CUpdateTest() in C:\Documents and Settings\bwagstaff\My Documents\Visual Studio 2005\Projects\GAPClientInfo\GAPClientInfo\GAPClientData.cs:line 147
at System.DateTimeParse.ParseExactMultiple(String s, String[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.DateTime.ParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style)
at System.Xml.XmlConvert.ToDateTime(String s, String[] formats)
at System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String value, String[] formats)
at System.Xml.Serialization.XmlCustomFormatter.ToDate(String value)
at System.Xml.Serialization.XmlSerializationReader.ToDate(String value)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSforceService.Read38_NullableOfDateTime(Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSforceService.Read39_Contact(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSforceService.Read109_sObject(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSforceService.Read123_QueryResult(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSforceService.Read157_queryResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer57.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

Message Edited by Bryan Wagstaff on 01-19-2006 04:15 PM

Can you get a capture of the SOAP response that causes the exception ?
Bryan WagstaffBryan Wagstaff
No, I have not been able to successfully capture the SOAP response. My packet analyzer only shows encrypted responses, which makes sense because it's through https.

Do you have a tool or function for that?
I typically use soapscope to capture the response, after forcing the URL to be HTTP for the suspect call.

A different approach is to extend the generated proxy class in .NET to log the response stream. (I think SforceExporer does this for example).
Bryan WagstaffBryan Wagstaff
I have a copy of the message. It is a few KB in size.

It seems that the sforce.query is dying on the first instance of LastModifiedDate.

The specific entity that it died on was

Looks fine to me, what version of .NET are you using ?
Bryan WagstaffBryan Wagstaff
Yeah, it looked fine to me too.

It's VS2005, and the normal .net version 2.0 (50727)

I could send the entire response over, but since it has a bunch of contacts in it, it would have to be through an email and not in public.
Bryan WagstaffBryan Wagstaff
Okay, this is really odd.

It just started working a few minutes ago.

I went back in build control and retried several of the executables I used today. Nearly all of them worked, and passed all the nunit tests as well.

I sure hope you changed something on your end ... I hate it when things spontaniously start working and I can't see an obvious reason why.


Message Edited by Bryan Wagstaff on 01-19-2006 04:25 PM

Nope, nothing has changed on our end today so far.
Bryan WagstaffBryan Wagstaff
Just a followup.

This problem has continued to be intermittent.  I have other exceptions that occur regularly (ahem, brief salesforce outages and bad connections :smileymad: ) and don't want to add more detection code to differentiate between the exceptions.  If there is an exception, I'll just abort and try again in five minutes.

I have not found a cause, but it always happens when the web service is trying to parse what looks to me like a valid date.  A single build of the application works for a while, then start getting the exception, then begins working again.

I don't know that anything I am doing is specifically causing a problem, as I'm using the web service wrapper from the demo apps and I'm not doing anything exotic with the connection.

Message Edited by Bryan Wagstaff on 03-03-2006 01:54 PM

I'm getting this issue as well.  My query is "select Id, Subject, OwnerId, WhatId, WhoId, LastModifiedDate from Task".  Has anyone found the cause of this problem?
Is this issue caused by ".Net Web Services currently do not recogize the "Z" timezone indicator."?
I am having the same problem obtaining the creation date for a case.

Was anyone able to get a resolution?