XML Service incorrectly and unpredictably parsing DateTime field?

That's definitely a weird case. A couple of things can alter the result of the parse.

That's definitely a weird case. A couple of things can alter the result of the parse. CultureInfo: by default Parse uses CurrentCulture.

If you have something funny on your globalization settings that triggers the change of your current culture, that could be affected. Per MSDN: 'The Parse method attempts to parse a string with several implicit parse patterns' and if you throw culture patterns in it, you can end up with quite a mess. My suggestions to try: Use the ParseExact method instead of Parse and enforce a format on your date time string.

Use InvariantCulture when parsing your date time (if your application date time format is universal, which I assume it is since you are storing ticks) On your setter try this: if (string. IsNullOrEmpty(value)) { this. Ticks = 0; } else { CultureInfo provider = CultureInfo.

InvariantCulture; var dateTime = DateTime. ParseExact(value, "yyyy-MM-dd hh:mm:ss", provider); this. Ticks = dateTime.ToUniversalTime().

Ticks; } Good luck! Edit 1 Something else came to my mind: ThreadSafety. If you are accessing the reflected object of Ticks (in your setter you do this.

Ticks) from multiple threads you should make it an atomic operation. //same setter code except last line... var oldTicks = this. Ticks; var newTicks = dateTime.ToUniversalTime().

Ticks; while(oldTicks! = Interlocked. Exchange(ref this.

Ticks, newTicks)) { //your break code here } Sorta :) Let me know if any of this helped to solve the mystery.

I haven't seen issues such as this, but did encounter problems where timezone information is lost from a . NET 2.0 SOAP webservice when the WebService method returns a DateTime rather than an object which contains DateTime. From that experience I learned that you should quickly focus on ensuring you can isolate and reproduce the problem.

I would suggest you build a test-harness. Using a sample DateTime value which you know has failed in your full system, emulate a client sending infinite requests. Run the service test-harness in Debug mode with a breakpoint to pause execution the moment it receives a value different from what was inspected.

Using a tool such as Fiddler to also capture the Client traffic can provide additional insight. If that fails to turn up the issue, then you should re-evaluate the evidence you have and again repeat the process as the next candidate is identified. Don't be afraid to retry something you believe you've tested or looked through before, the devil is nearly always in the details with these.

One other thought -- is it possible that this could be a concurrency/multithreading issue? If you have hard evidence that a particular value was submitted and a different value was received, then have you looked to ensure the received value was sent by a different client--or could be set from a different location within the system?

You can fix these issues by stating that all transported dates (moved between remote systems) are in fact UTC, for example: public DateTime StartDateUtc { ... } public DateTime EndDateUtc { ... } And you leave the responsability of conversion to and from local time only to user interfaces code (or the highest layers of your application). Note you can't really enforce this technically, only by convention / documentation, and making sure properties and methods are semantically marked "as UTC". A bad programmer will always be able to pass a local date to these properties: StartDateUtc = DateTime.

UtcNow; // this is correct StartDateUtc = DateTime. Now; // this is wrong.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions