- Home
- LLBLGen Pro
- Bugs & Issues
Serialization and Deserialization problem
Posts
Posts: 41
Joined: 19-Nov-2006
Joined: 19-Nov-2006
# Posted on: 20-Mar-2007 19:57:44
FileVersion 2.0.7.122 Adapter SQL Server 2005
Hello,
when trying to serialize classes based on LLBL, I am having the following error (occured in one of my LLBL generated classes):
"Cannot add the same member twice to a SerializationInfo object."
below my class that I want to be able to serialize:
public interface IMyUser
{
string AuthenticationType { get; }
decimal DocIId { get; }
EntityCollection<TEditeursEntity> Editeurs { get; }
EntityCollection<TpInternalFunctionEntity> InternalFunction { get; }
bool IsAuthenticated { get; }
string Name { get; }
string Roles { get; }
string WorkingEditeurTxt { get; }
EntityCollection<TEditeursEntity> SelectedEditeurs { get; set; }
TEditeursEntity WorkingEditeur { get; set; }
}
below the method to serialize/deserialize:
private void BinarySerialize(IMyUser toSerialize)
{
using (FileStream str = File.Create("user.bin"))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(str, toSerialize);
}
}
private void BinaryDeserialize()
{
IMyUser toDeserialize = null;
using (FileStream str = File.OpenRead("user.bin"))
{
BinaryFormatter bf = new BinaryFormatter();
toDeserialize = (IMyUser)bf.Deserialize(str);
}
}
Below is my stackTrace:
System.Runtime.Serialization.SerializationException was unhandled
Message="Cannot add the same member twice to a SerializationInfo object."
Source="mscorlib"
StackTrace:
at System.Runtime.Serialization.SerializationInfo.AddValue(String name, Object value, Type type)
at System.Runtime.Serialization.SerializationInfo.AddValue(String name, Object value)
at Aldabra.Magellan.DAL.EntityClasses.TDocumentsEntity.GetObjectData(SerializationInfo info, StreamingContext context) in D:\Aldabra.com\DAL\LLBL\DatabaseGeneric\EntityClasses\TDocumentsEntity.cs:line 358
at Aldabra.Magellan.DAL.EntityClasses.TContactsEntity.GetObjectData(SerializationInfo info, StreamingContext context) in D:\Aldabra.com\DAL\LLBL\DatabaseGeneric\EntityClasses\TContactsEntity.cs:line 587
at Aldabra.Magellan.DAL.EntityClasses.TPersonnesEntity.GetObjectData(SerializationInfo info, StreamingContext context) in D:\Aldabra.com\DAL\LLBL\DatabaseGeneric\EntityClasses\TPersonnesEntity.cs:line 392
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at Serialize.Form1.BinarySerialize(IMagellanUser toSerialize) in E:\Documents\Visual Studio 2005\Projects\Tests\Serialize\Serialize\Form1.cs:line 23
at Serialize.Form1.button2_Click(Object sender, EventArgs e) in E:\Documents\Visual Studio 2005\Projects\Tests\Serialize\Serialize\Form1.cs:line 50
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods. IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Serialize.Program.Main() in E:\Documents\Visual Studio 2005\Projects\Tests\Serialize\Serialize\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
btw, I am having the folowing hierarchy: TDocuments<-TContacts<-TPersonnes
Thanks,