It is a bug that will be fixed in the next version. One way to work around this is to make your type (struct Temp) Iserialzable and write the decimal as string using the ToString() method and read using Decimal.Parse(str, NumberStyles.Float)
Hope this helps Sowmy -----Original Message----- From: S�ren Mondrup [mailto:soren@;EDLUND.DK] Sent: Thursday, November 07, 2002 2:19 AM To: [EMAIL PROTECTED] Subject: [ADVANCED-DOTNET] BUG: Serialization of decimals less than 1E-4 Both the BinaryFormatter and SoapFormatter fails when deserializing decimals with a value between 0 an 1E-4. The problem seems to be that the small decimals are serialized in scientific notation, which Decimal.Parse () won't accept. This must be a bug. Does any of you know how to get arround it? I could write my own decimal struct, but it would be hard to enforce using this new struct in our code. I could also write my own serializer, but that seems to be a lot of work. I would rather intercept either the serialization or deserialization of decimals. Is that even possible? TIA S�ren The c# code below demonstrates the bug: ------------------------------------------ using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; namespace ConsoleApplication1 { [Serializable] public struct Temp { public decimal num1; } class Class1 { static void Main(string[] args) { Temp x = new Temp(); x.num1 = 0.00001M; // Is serialized to "1E-05" which // fails on deserialization. //x.num1 = 0.0001M; // OK. Serialized to "0.0001". Stream s1 = File.Open("C:\\Temp.bin", FileMode.Create); BinaryFormatter f1 = new BinaryFormatter(); f1.Serialize(s1, x); s1.Close(); Stream s2 = File.Open("C:\\Temp.bin", FileMode.Open); BinaryFormatter f2 = new BinaryFormatter(); Temp y = (Temp)f2.Deserialize(s2); s2.Close(); } } } You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.
