.NET 2.0 WSDL DateTime Parsing Bug

I've built a wrapper application that abstracts Salesforce.com integration with our CRM, and came across a bit of an obscure bug yesterday.

The issue came up when assigning a .NET DateTime value to a DateTime field in the generated SFDC proxy:

 

SFDCObject__c _sfdcObject = new SFDCObject__c();
_sfdcObject.Created_Date__c = DateTime.Now;
_sfdcObject.Created_Date__cSpecified = true;

 

When assigning the .NET DateTime value to the _sfdcObject.Created_Date__c member, an error is thrown:

 

ex = {"'2008-02-20' is not a valid value for the type xsd:dateTime"}

 

A bit of digging brought up this thread on the Salesforce.com developer discussion boards.  It turns out that the culprit is actually a bug in .NET 2.0 (quote is from the discussion thread):

If a schema contains both “xsd:date” with nillable=true and “xsd:dateTime” with nillable=true, we will import either both as “date” or both as “dateTime”. In your case, both probably get imported as “date”, hence the time component cases a failure. This is a known bug and there is a hotfix available (KB 925272), available by calling PSS.

The hotfix would need to be installed on all servers and dev machines, which seems like a non-optimal solution, so I went with the workaround of hand-modifying the WSDL to replace all instances of "xsd:date" with "xsd:dateTime".  This worked for me because my application only needs to work with SFDC objects that are defined as "xsd:dateTime".  If you have an app that needs to work with both xsd:date and xsd:dateTime typed fields, you will most likely need to install the hotfix from Microsoft, or move your solution to .NET 3.0 or 3.5.

No Comments