By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,678 Members | 1,288 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,678 IT Pros & Developers. It's quick & easy.

Serialize Class To XML

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.