All I Am Attempting To Serialize An Object To An XML File.
Here Is The Code For That
public string SaveNewSurvey( MutualSurveyObj ect
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName ;
try
{
//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToStrin g() + "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(
MutualSurveyObj ect ) );
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.S erializationExc eption: The
type FNIS.MutualSurv eyApplication.M utualSurveyObje ct in
Assembly MutualSurveyStr uctureObject,
Version=1.0.141 1.14253, Culture=neutral ,
PublicKeyToken= null is not marked as serializable.
Server stack trace:
at
System.Runtime. Serialization.F ormatterService s.InternalGetS
erializableMemb ers(RuntimeType type, Boolean
excludeNonSeria lizable)
at
System.Runtime. Serialization.F ormatterService s.GetSerializa
bleMembers(Type type, StreamingContex t context)
at
System.Runtime. Serialization.F ormatters.Binar y.WriteObjectI
nfo.InitMemberI nfo()
at
System.Runtime. Serialization.F ormatters.Binar y.WriteObjectI
nfo.InitSeriali ze(Object obj, ISurrogateSelec tor
surrogateSelect or, StreamingContex t context,
SerObjectInfoIn it serObjectInfoIn it, IFormatterConve rter
converter)
at
System.Runtime. Serialization.F ormatters.Binar y.WriteObjectI
nfo.Serialize(O bject obj, ISurrogateSelec tor
surrogateSelect or, StreamingContex t context,
SerObjectInfoIn it serObjectInfoIn it, IFormatterConve rter
converter)
at
System.Runtime. Serialization.F ormatters.Binar y.ObjectWriter
..Serialize(Obj ect graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormat
ter.Serialize(S tream serializationSt ream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormat
ter.Serialize(S tream serializationSt ream, Object graph,
Header[] headers)
at
System.Runtime. Remoting.Channe ls.CoreChannel. SerializeBinar
yMessage(IMessa ge msg, Stream outputStream, Boolean
includeVersions )
at
System.Runtime. Remoting.Channe ls.BinaryClient FormatterSink.
SerializeMessag e(IMessage msg, ITransportHeade rs& headers,
Stream& stream)
at
System.Runtime. Remoting.Channe ls.BinaryClient FormatterSink.
SyncProcessMess age(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
Here Is The Code For That
public string SaveNewSurvey( MutualSurveyObj ect
mso_TempObject, int i_JobID )
{
string s_RootFileName;
string s_FinalFileName ;
try
{
//Create The Final File Name
s_RootFileName = "job" + i_JobID.ToStrin g() + "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(
MutualSurveyObj ect ) );
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.S erializationExc eption: The
type FNIS.MutualSurv eyApplication.M utualSurveyObje ct in
Assembly MutualSurveyStr uctureObject,
Version=1.0.141 1.14253, Culture=neutral ,
PublicKeyToken= null is not marked as serializable.
Server stack trace:
at
System.Runtime. Serialization.F ormatterService s.InternalGetS
erializableMemb ers(RuntimeType type, Boolean
excludeNonSeria lizable)
at
System.Runtime. Serialization.F ormatterService s.GetSerializa
bleMembers(Type type, StreamingContex t context)
at
System.Runtime. Serialization.F ormatters.Binar y.WriteObjectI
nfo.InitMemberI nfo()
at
System.Runtime. Serialization.F ormatters.Binar y.WriteObjectI
nfo.InitSeriali ze(Object obj, ISurrogateSelec tor
surrogateSelect or, StreamingContex t context,
SerObjectInfoIn it serObjectInfoIn it, IFormatterConve rter
converter)
at
System.Runtime. Serialization.F ormatters.Binar y.WriteObjectI
nfo.Serialize(O bject obj, ISurrogateSelec tor
surrogateSelect or, StreamingContex t context,
SerObjectInfoIn it serObjectInfoIn it, IFormatterConve rter
converter)
at
System.Runtime. Serialization.F ormatters.Binar y.ObjectWriter
..Serialize(Obj ect graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormat
ter.Serialize(S tream serializationSt ream, Object graph,
Header[] headers, Boolean fCheck)
at
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormat
ter.Serialize(S tream serializationSt ream, Object graph,
Header[] headers)
at
System.Runtime. Remoting.Channe ls.CoreChannel. SerializeBinar
yMessage(IMessa ge msg, Stream outputStream, Boolean
includeVersions )
at
System.Runtime. Remoting.Channe ls.BinaryClient FormatterSink.
SerializeMessag e(IMessage msg, ITransportHeade rs& headers,
Stream& stream)
at
System.Runtime. Remoting.Channe ls.BinaryClient FormatterSink.
SyncProcessMess age(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
Comment