Hi,
I have a web service method which takes a DateTime type as a parameter.
The service is UK based, and the dates are passed in to the service in the
UK format dd/MM/yyyy.
On a recent install, the web service method will not accept the UK date
format, erroring with a System.Argument exception, but would take US
formatted dates.
As the DateTime type is a method parameter, I cannot use an IFormatProvider
to Parse the date, and check for any errors. What appears to be happening is
that the Web Service code which runs before my method code runs is trying to
Parse the date, but why would it choose US date?
All locale settings on the machine are English (United Kingdom). I have
checked all the the registry entries under HKU -> S....... -> Control Panel
-> International, and they are all set to English (United Kingdom). I have
also set the globalization element in the web.config file for both the
CurrentCulture and CurrentUICulture to en-GB.
So this appears to be the .NET framework code, perhaps as a result of the
[WebMethod] attribute, deserializing the date, and attempting to create a
DateTime object on behalf of the method, but why is it choosing the en-US
method??
Stack Trace
System.ArgumentException: Cannot convert 31/03/2006 to System.DateTime.
Parameter name: type ---> System.FormatException: String was not recognized
as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)
at System.Convert.ToDateTime(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToDateTime(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType,
IFormatProvider provider)
at System.Web.Services.Protocols.ScalarFormatter.FromString(String value,
Type type)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.ScalarFormatter.FromString(String value,
Type type)
at
System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest
request)
at System.Web.Services.Protoco
Any help would be greatly appreciated.
Rich
Pablo Cibraro - 17 Jul 2006 15:35 GMT
Hi Rich,
Did you check the culture infor for the current thread ?.
System.Globalization.CultureInfo ci =
System.Threading.Thread.CurrentThread.CurrentCulture;
If that CultureInfo instance is US, some globalization setting is not being
applied correctly in your application.
Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax
[MVP - Connected Systems Developer]
> Hi,
>
[quoted text clipped - 58 lines]
>
> Rich
Tihomir - 10 Aug 2006 14:19 GMT
> Hi,
>
[quoted text clipped - 48 lines]
>
> Rich
I have the samo error in my multilanguage aplication.
i got this error when i receave data like this 10.23.2006 or 10/23/2006 so i did something simple.Just change the place of Month and Day (from 10.23.2006 to 23.10.2006) and i have no more this problem :P
Posted from http://www.topxml.com/renntp using reNNTP: the website based NNTP reader.
Peter Ritchie [C# MVP] - 07 Sep 2006 20:47 GMT
Is the client computer configured for US English?

Signature
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
> Hi,
>
[quoted text clipped - 48 lines]
>
> Rich