webservice service System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)

Xu Li 5 Reputation points
2024-07-04T03:09:31.28+00:00

I am currently encountering an issue with a web service. The server-side field MinimumOrderAmount is of type double, and in my receiving program, I have defined it as decimal. When the server sends a value of 9999999999 for MinimumOrderAmount, my program throws an error with the following message:


Exception thrown passed to this Web service: System.InvalidOperationException: There is an error in XML document (1, 3998). ---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderAvailabilityService.Read13_VoucherDiscount(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderAvailabilityService.Read90_RoomRate(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderAvailabilityService.Read141_RoomStay(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderAvailabilityService.Read142_AvailResponseSegment(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderAvailabilityService.Read143_AvailabilityResponse(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderAvailabilityService.Read191_AvailabilityResponse()
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

Theoretically, a double type should be able to be directly converted to a decimal type. Why does this conversion fail when the value is 9999999999, but succeeds when the value is 999999999 (9 digits)?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,643 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,417 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,642 questions
{count} votes