473,416 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Serialize Class To XML

Dan
All I Am Attempting To Serialize An Object To An XML File.
Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml";
s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS
erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa
bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter
..Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat
ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat
ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar
yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink.
SerializeMessage(IMessage msg, ITransportHeaders& headers,
Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink.
SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

Nov 15 '05 #1
10 4111
The exception tells you the problem You haven't marked the object you're
trying to serialize as serializable.

Check out the SerializableAttribute

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File.
Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml";
s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS
erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa
bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter
.Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat
ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat
ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar
yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink.
SerializeMessage(IMessage msg, ITransportHeaders& headers,
Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink.
SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

Nov 15 '05 #2
Dan,

Are you sure you are using an XML serializer here? The stack trace you
provide hints that binary serialization is being used somewhere, in which
case, you need to make sure that a type and all the types it references are
marked as serializable.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File.
Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml";
s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS
erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa
bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter
.Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat
ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat
ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar
yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink.
SerializeMessage(IMessage msg, ITransportHeaders& headers,
Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink.
SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

Nov 15 '05 #3
I assume your class is marked as Serializable, but you also need to check
that every object it contains is also either marked as Serializable itself
or marked as NonSerialized in your class.
"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File.
Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml";
s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS
erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa
bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter
.Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat
ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat
ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar
yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink.
SerializeMessage(IMessage msg, ITransportHeaders& headers,
Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink.
SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

Nov 15 '05 #4
Dan
Bob And Nicholas,

Thanks for the quick replies. They are appreciated.

I want to make sure I am clear. In the class I am
attempting to Serialize I need to mark each element as
Serializable: is that correct? Some of the examples I
looked at did not mark the elements which gave me the
impression that you only marked those elements that you
wanted more control over.

Dan

-----Original Message-----
The exception tells you the problem You haven't marked the object you'retrying to serialize as serializable.

Check out the SerializableAttribute

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml"; s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter .Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SerializeMessage(IMessage msg, ITransportHeaders& headers, Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

.

Nov 15 '05 #5
Dan,

You should not have to mark the elements as Serializable. This is
required for formal serialization (using an IFormatter implementation), not
XML serialization.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <an*******@discussions.microsoft.com> wrote in message
news:22****************************@phx.gbl...
Bob And Nicholas,

Thanks for the quick replies. They are appreciated.

I want to make sure I am clear. In the class I am
attempting to Serialize I need to mark each element as
Serializable: is that correct? Some of the examples I
looked at did not mark the elements which gave me the
impression that you only marked those elements that you
wanted more control over.

Dan

-----Original Message-----
The exception tells you the problem You haven't marked

the object you're
trying to serialize as serializable.

Check out the SerializableAttribute

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml"; s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter .Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SerializeMessage(IMessage msg, ITransportHeaders& headers, Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

.

Nov 15 '05 #6
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconintroducing
xmlserialization.htm
and

http://msdn.microsoft.com/library/de...ialization.asp

"Dan" <an*******@discussions.microsoft.com> wrote in message
news:22****************************@phx.gbl...
Bob And Nicholas,

Thanks for the quick replies. They are appreciated.

I want to make sure I am clear. In the class I am
attempting to Serialize I need to mark each element as
Serializable: is that correct? Some of the examples I
looked at did not mark the elements which gave me the
impression that you only marked those elements that you
wanted more control over.

Dan

-----Original Message-----
The exception tells you the problem You haven't marked

the object you're
trying to serialize as serializable.

Check out the SerializableAttribute

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml"; s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter .Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SerializeMessage(IMessage msg, ITransportHeaders& headers, Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

.

Nov 15 '05 #7
Dan
Matt,

I am a bit confused. Looking at a simple example on MSDN I
don't see what you are refering to. Here is their class

public class OrderForm{
public DateTime OrderDate;
}

What kind of marking is needed? Thanks for the help. I
appreciate it.

Dan
-----Original Message-----
I assume your class is marked as Serializable, but you also need to checkthat every object it contains is also either marked as Serializable itselfor marked as NonSerialized in your class.
"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml"; s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter .Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SerializeMessage(IMessage msg, ITransportHeaders& headers, Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

.

Nov 15 '05 #8
Here's the deal (as I understand it), if you have a class like this:

[Serializable]
public class A
{
public B myB;
....
}

public class B
{
.....
}

And you want to serialize class A, you must:
- Mark class A with the Serializable attribute (which I've done here)
- Mark class B as Serializable as well because class A contains an
instance of class B (which I haven't done)
- Alternatively, I could mark the field myB as NonSerializable in the
definition of class A like this:

[NonSerialized()]
public B myB;

This will mean, however, that myB will not get saved when you serialize and
thus won't get restored when you reload it. Sometimes this might be exactly
what you want (for example if you class contains a reference to a form, you
probably don't want to save the entire form as well as the object itself).
Every field in your class that your are serializing must either:
- Be one of the base types (int, bool, etc) - in which case serialization is
already handled
- Be one of the framework types which is already marked as serializable (I
don't think they all are, check MSDN)
- Be of a type that is itself marked as Serializable in it's own definition
- Be marked as NonSerializable in your class definition - which means it
won't be saved

Hope that helps

"Dan" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Matt,

I am a bit confused. Looking at a simple example on MSDN I
don't see what you are refering to. Here is their class

public class OrderForm{
public DateTime OrderDate;
}

What kind of marking is needed? Thanks for the help. I
appreciate it.

Dan
-----Original Message-----
I assume your class is marked as Serializable, but you

also need to check
that every object it contains is also either marked as

Serializable itself
or marked as NonSerialized in your class.
"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml"; s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter .Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SerializeMessage(IMessage msg, ITransportHeaders& headers, Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

.

Nov 15 '05 #9
To clarify..

Mark the class as serializable..

[Serializable()]
class MyClass
{
}

All public properties will be serialized. If you have objects in those
properties they will also need to be marked as serializable.

If you don't want a particlar property to be serialized as XML mark it as
XmlIgnore()...

[XmlIgnore()]
public int MyNonSerializedInt
{
get...
set...
}

If you want to change the name of a property to something else use the
XmlElement attribute...

[XmlElement("X")]
public int MyRidiculouslyUnweildyAndGratuituoslyLongNamedIntP roperty
{
get...
set...
}

HTH

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Dan" <an*******@discussions.microsoft.com> wrote in message
news:22****************************@phx.gbl...
Bob And Nicholas,

Thanks for the quick replies. They are appreciated.

I want to make sure I am clear. In the class I am
attempting to Serialize I need to mark each element as
Serializable: is that correct? Some of the examples I
looked at did not mark the elements which gave me the
impression that you only marked those elements that you
wanted more control over.

Dan

-----Original Message-----
The exception tells you the problem You haven't marked

the object you're
trying to serialize as serializable.

Check out the SerializableAttribute

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Dan" <dd*****@fnisolutions.com> wrote in message
news:22****************************@phx.gbl...
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That

public string SaveNewSurvey( MutualSurveyObject
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName;

try
{

//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToString() + "config.xml"; s_FinalFileName =
s_SetUpFilePath + @"\" + s_RootFileName;

//Serialize The Object And Write The XML Data
TextWriter tr = new StreamWriter( s_FinalFileName );
XmlSerializer sr = new XmlSerializer( typeof(
MutualSurveyObject ) );
sr.Serialize( tr, mso_TempObject );
tr.Close();

return s_RootFileName;

}

catch ( Exception e )
{
throw e;
}
}

However, When I attempt to execute this I get the
following rather long Exception message

System.Runtime.Serialization.SerializationExceptio n: The
type FNIS.MutualSurveyApplication.MutualSurveyObject in
Assembly MutualSurveyStructureObject,
Version=1.0.1411.14253, Culture=neutral,
PublicKeyToken=null is not marked as serializable.

Server stack trace:
at
System.Runtime.Serialization.FormatterServices.Int ernalGetS erializableMembers(RuntimeType type, Boolean
excludeNonSerializable)
at
System.Runtime.Serialization.FormatterServices.Get Serializa bleMembers(Type type, StreamingContext context)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.InitSerialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI nfo.Serialize(Object obj, ISurrogateSelector
surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter)
at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter .Serialize(Object graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormat ter.Serialize(Stream serializationStream, Object graph,
Header[] headers)
at
System.Runtime.Remoting.Channels.CoreChannel.Seria lizeBinar yMessage(IMessage msg, Stream outputStream, Boolean
includeVersions)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SerializeMessage(IMessage msg, ITransportHeaders& headers, Stream& stream)
at
System.Runtime.Remoting.Channels.BinaryClientForma tterSink. SyncProcessMessage(IMessage msg)
The object is complete in terms of being one object that
holds collections of other objects. Is that the problem?
I am lost. Any help would be appreciated.

Dan

.

Nov 15 '05 #10
Dan
To Bob, Nicholas, Matt, and the one unknown responder.

Thank you so much for taking the time to answer my
questions. Because you were all kind enough to take 5
minutes out of your day and respond, you have saved me
countless hours of frustration and head pounding. I am
happy to say my object is being searlized into a beautiful
xml file.

Thanks again!!!!!

Dan
Nov 15 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael | last post by:
Hi I anyone have a clue or can solve my problem I would be glad :-) Regards Michael I have a problem with creating an XML-document where the returning data from the webservice, have been...
3
by: CLEAR-RCIC | last post by:
Hi, I have a class that I am trying to serialize. To simplify, I've changed the names to Baseball, Teams and Players. Here is what the XML should look like: <BaseBall> <Teams> <Team>...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
3
by: MAY | last post by:
Hi, I have a problem about serialize the form controls. I wrote a test program to test serialize a from but fail (->An unhandled exception of type...
3
by: Jerry | last post by:
Hi, I have a class like the following: class A { private B _b; A (B b) { _b = b; } ...
2
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
7
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a...
4
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.