Problem with Deserialization

G

Gaurav Nanda

Hi,

I am creating a excel plugin, where i have to create a Tree on Excel
worksheet, so while saving i also want to save the tree in serialized form as
a custom property of worksheet.

Hence, i am using a BinaryFormatter, which serializes the Tree object and
saves the result in form of a string and attach it to a cutom property of
sheet.This Works fine.

[Tree is comprised of nodes(NODE class, also marked serializable)], While
De-serializing, it works fine , untill number of nodes in tree exceeds 24.So
when N(nodes) >24 , i get two types of exceptions, any one of them randomly.

1)
at System.Runtime.Serialization.ObjectManager.RegisterObject(Object obj,
Int64 objectID, SerializationInfo info, Int64 idOfContainingObj, MemberInfo
member, Int32[] arrayIndex)
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject(Object obj, ParseRecord pr, ParseRecord objectPr, Boolean bIsString)
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObjectEnd(ParseRecord pr)
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at ProbTreeDemo.Connect.WorkBookOpened(Workbook myWorkBook) in
C:\Docs\Visual Studio 2005\Projects\ProbTreeDemo\Connect.cs:line 286

Error Message :- An object cannot be registered twice.

2)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo
culture, BindingFlags invokeAttr)
at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object
value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean
doVisibilityCheck, Boolean doCheckConsistency)
at
System.Runtime.Serialization.FormatterServices.SerializationSetValue(MemberInfo fi, Object target, Object value)
at
System.Runtime.Serialization.FormatterServices.PopulateObjectMembers(Object
obj, MemberInfo[] members, Object[] data)
at
System.Runtime.Serialization.Formatters.Binary.ReadObjectInfo.PopulateObjectMembers(Object obj, Object[] memberData)
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObjectEnd(ParseRecord pr)
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord
pr)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain,
IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck, Boolean
isCrossAppDomain, IMethodCallMessage methodCallMessage)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
at ProbTreeDemo.Connect.WorkBookOpened(Workbook myWorkBook) in
C:\Docs\Visual Studio 2005\Projects\ProbTreeDemo\Connect.cs:line 286

Error Message:- Object of type 'ProbTreeDemo.TreeStructure.Node' cannot be
converted to type 'System.Object[]'.

Source is botth cases is "mscorlib".
Code at line 286:- Tree temp =(Tree)bformatter.Deserialize(stream);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top