[Mono-list] Serialization of custom key in Dictionary

JensAernouts jens.aernouts at student.artesis.be
Tue Mar 15 12:34:19 EDT 2011


Owkey, here is some code:

Next function serializes the value of my dictionary:
public Dictionary<string, byte[]>
measurementModelsToStream(Dictionary<string, IMeasurementModel>
measurementModels)
        {
            Dictionary<string, byte[]> newDict = new
Dictionary<string, byte[]>();
            MemoryStream ms = new MemoryStream();
            foreach (KeyValuePair<string, IMeasurementModel>
measurementModel in measurementModels)
            {
                ms = infoToStream(measurementModel.Value);
                newDict.Add(measurementModel.Key, ms.ToArray());
            }
            return newDict;
        }

'IMeasurementModel' is a an interface to different classes, where in every
class there is at least one Dictionary like this:
'Dictionary<FingerPrint, double>()'. 'FingerPrint' is also a class
that I use... All classes (FingerPrint, the different MeasurementModels,
...) are marked as serializable with the '[serializable]' line, so I don't
think I do anything wrong.
To Deserialize, I use next:
        public Dictionary<string, IMeasurementModel>
streamToMeasurementModelDict(Dictionary<string, byte[]>
measurementModelsIn)
        {
            Dictionary<string, IMeasurementModel> newDict = new
Dictionary<string, IMeasurementModel>();
            foreach (KeyValuePair<string, byte[]> measurementModel in
measurementModelsIn)
            {
                MemoryStream memStream = new MemoryStream();
                BinaryFormatter binForm = new BinaryFormatter();
                memStream.Write(measurementModel.Value, 0,
measurementModel.Value.Length);
                memStream.Seek(0, SeekOrigin.Begin);
                object obj = binForm.Deserialize(memStream);
                newDict.Add(measurementModel.Key, (IMeasurementModel)obj);
            }
            return newDict;
        }

All the above is working well when I use windows computers, but when I
migrate to linux and run the built exe with Mono, it gives the exception
mentioned in the first post... I don't know what I'm doing wrong...

Kind Regards

--
View this message in context: http://mono.1490590.n4.nabble.com/Serialization-of-custom-key-in-Dictionary-tp3356761p3357092.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list