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)?

Developer technologies .NET Other
Developer technologies ASP.NET Other
Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.