将类序列化为XML [英] Serialize Class To XML

查看:85
本文介绍了将类序列化为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将对象序列化为XML文件。

以下是代码:

公共字符串SaveNewSurvey(MutualSurveyObject
mso_TempObject,int i_JobID)

{

string s_RootFileName;

string s_FinalFileName;


尝试

{


//创建最终文件名

s_RootFileName =" job" + i_JobID.ToString()+" config.xml";

s_FinalFileName =

s_SetUpFilePath + @" \" + s_RootFileName;


//序列化对象并写入XML数据

TextWriter tr = new StreamWriter(s_FinalFileName);

XmlSerializer sr = new XmlSerializer(typeof(

MutualSurveyObject));

sr.Serialize(tr,mso_TempObject);

tr.Close() ;


返回s_RootFileName;


}


catch(例外e)

{

扔e;

}

}


然而,当我试图执行这个我得到

跟随相当长的异常消息


System.Runtime.Serialization.SerializationExceptio n:

类型为FNIS.MutualSurveyApplication.MutualSurveyObject

汇编MutualSurveyStructureObject,

Version = 1.0.1411.14253,Culture = neutral,

PublicKeyToken = null未标记可序列化。


服务器堆栈跟踪:

at

System.Runtime.Serialization.FormatterServi ces.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.Ser ialization.Formatters.Binary.Obj ectWriter

..Serialize(对象图,Header [] inHeaders,

__BinaryWriter serWriter,Boolean fCheck)

at

System.Runtime.Serialization.Formatters.Binary.Bin aryFormat

ter.Serialize(Stream serializationStream,Object graph,

Header [] header,Boolean fCheck)

at

System.Runtime.Serialization.Formatters.Binary.Bin aryFormat

ter.Serialize(Stream serializationStream,Object图表,

标题[]标题)

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&标题,

Stream&

at

System.Runtime.Remoting.Channels.BinaryClientForma tterSink。

SyncProcessMessage(IMessage msg)

对象是一个对象是完整的,

包含其他对象的集合。这是问题吗?

我迷路了。任何帮助将不胜感激。


Dan

解决方案

该例外告诉您问题你没有标记对象你是否b / b
尝试序列化为可序列化。


查看SerializableAttribute


-

Bob Powell [MVP]

C#,System.Drawing


十月版Well Formed现在可用。

了解如何在Windows窗体控件中使用DirectX
http://www.bobpowell.net/currentissue.htm

用GDI +常见问题回答那些GDI +问题
http://www.bobpowell.net/gdiplus_faq.htm


http://bobpowelldotnet.blogspot.com 上阅读我的博客


" Dan" <峰; dd ***** @ fnisolutions.com>在消息中写道

news:22 **************************** @ phx.gbl ... < blockquote class =post_quotes>我试图将对象序列化为XML文件。
这是代码的公共字符串SaveNewSurvey(MutualSurveyObject
mso_TempObject,int i_JobID)
{
字符串s_RootFileName;
字符串s_FinalFileName;

尝试
{

//创建最终文件名
s_RootFileName =" job" + i_JobID.ToString()+" config.xml";
s_FinalFileName =
s_SetUpFilePath + @" \" + s_RootFileName;

//序列化对象并编写XML数据
TextWriter tr = new StreamWriter(s_FinalFileName);
XmlSerializer sr = new XmlSerializer(typeof(
MutualSurveyObject));
sr.Serialize(tr,mso_TempObject);
tr.Close();

返回s_RootFileName;

}

catch(例外e)
{
扔e;
}
}
然而,当我尝试执行此操作时,我得到了
以下相当长的异常消息

System.Runtime.Serialization.SerializationExceptio n:
类型FNIS.MutualSurveyApplication.MutualSurveyObject在
程序集MutualSurveyStructureObject中,
Version = 1.0.1411.14253,Culture = neutral,
PublicKeyToken = null未标记为可序列化。

服务器堆栈跟踪:
在System.Runtime.Serialization。 FormatterServices.Int ernalGetS
erializableMembers(RuntimeType type,Boolean
excludeNonSerializable)

S ystem.Runtime.Serialization.FormatterServices.Get Serializa
bleMembers(Type type,StreamingContext context)
在System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitMemberInfo ()
在System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitSerialize(Object obj,ISurrogateSelector
surrogateSelector,StreamingContext context,
SerObjectInfoInit serObjectInfoInit ,IFormatterConverter
转换器)
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.Serialize(Object obj,ISurrogateSelector
surrogateSelector,StreamingContext context,
SerObjectInfoInit serObjectInfoInit,IFormatterConverter
转换器)
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter
.Serialize(Object graph,Header [] inHeaders,
__BinaryWriter serWriter,Boolean fCheck)
在System.Runtime.Serialization.Formatters.Binary.Bin a ryFormat
ter.Serialize(Stream serializationStream,Object graph,
Header [] headers,Boolean fCheck)
在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)
在System.Runtime.Remoting.Channels.BinaryClientForma tterSink。
SerializeMessage(IMessage msg,ITransportHeaders&标题,
Stream&在/或System.Runtime.Remoting.Channels.BinaryClientForma tterSink。
SyncProcessMessage(IMessage msg)

对象是一个对象是完整的
包含其他对象的集合。这是问题吗?
我迷路了。任何帮助将不胜感激。

Dan



Dan,


你是确定你在这里使用XML序列化器?堆栈跟踪你

提供二进制序列化正在某处使用的提示,其中

情况,你需要确保一个类型及它引用的所有类型

标记为可序列化。


希望这会有所帮助。

-

- Nicholas Paldino [。 NET / C#MVP]

- mv*@spam.guard.caspershouse.com

丹 <峰; dd ***** @ fnisolutions.com>在消息中写道

news:22 **************************** @ phx.gbl ... < blockquote class =post_quotes>我试图将对象序列化为XML文件。
这是代码的公共字符串SaveNewSurvey(MutualSurveyObject
mso_TempObject,int i_JobID)
{
字符串s_RootFileName;
字符串s_FinalFileName;

尝试
{

//创建最终文件名
s_RootFileName =" job" + i_JobID.ToString()+" config.xml";
s_FinalFileName =
s_SetUpFilePath + @" \" + s_RootFileName;

//序列化对象并编写XML数据
TextWriter tr = new StreamWriter(s_FinalFileName);
XmlSerializer sr = new XmlSerializer(typeof(
MutualSurveyObject));
sr.Serialize(tr,mso_TempObject);
tr.Close();

返回s_RootFileName;

}

catch(例外e)
{
扔e;
}
}
然而,当我尝试执行此操作时,我得到了
以下相当长的异常消息

System.Runtime.Serialization.SerializationExceptio n:
类型FNIS.MutualSurveyApplication.MutualSurveyObject在
程序集MutualSurveyStructureObject中,
Version = 1.0.1411.14253,Culture = neutral,
PublicKeyToken = null未标记为可序列化。

服务器堆栈跟踪:
在System.Runtime.Serialization。 FormatterServices.Int ernalGetS
erializableMembers(RuntimeType type,Boolean
excludeNonSerializable)

S ystem.Runtime.Serialization.FormatterServices.Get Serializa
bleMembers(Type type,StreamingContext context)
在System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitMemberInfo ()
在System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitSerialize(Object obj,ISurrogateSelector
surrogateSelector,StreamingContext context,
SerObjectInfoInit serObjectInfoInit ,IFormatterConverter
转换器)
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.Serialize(Object obj,ISurrogateSelector
surrogateSelector,StreamingContext context,
SerObjectInfoInit serObjectInfoInit,IFormatterConverter
转换器)
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter
.Serialize(Object graph,Header [] inHeaders,
__BinaryWriter serWriter,Boolean fCheck)
在System.Runtime.Serialization.Formatters.Binary.Bin a ryFormat
ter.Serialize(Stream serializationStream,Object graph,
Header [] headers,Boolean fCheck)
在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)
在System.Runtime.Remoting.Channels.BinaryClientForma tterSink。
SerializeMessage(IMessage msg,ITransportHeaders&标题,
Stream&在/或System.Runtime.Remoting.Channels.BinaryClientForma tterSink。
SyncProcessMessage(IMessage msg)

对象是一个对象是完整的
包含其他对象的集合。这是问题吗?
我迷路了。任何帮助将不胜感激。

Dan



我假设您的班级被标记为可序列化,但您还需要检查

它包含的每个对象也被标记为Serializable本身

或在你的班级中标记为NonSerialized。

Dan <峰; dd ***** @ fnisolutions.com>在消息中写道

news:22 **************************** @ phx.gbl ... < blockquote class =post_quotes>我试图将对象序列化为XML文件。
这是代码的公共字符串SaveNewSurvey(MutualSurveyObject
mso_TempObject,int i_JobID)
{
字符串s_RootFileName;
字符串s_FinalFileName;

尝试
{

//创建最终文件名
s_RootFileName =" job" + i_JobID.ToString()+" config.xml";
s_FinalFileName =
s_SetUpFilePath + @" \" + s_RootFileName;

//序列化对象并编写XML数据
TextWriter tr = new StreamWriter(s_FinalFileName);
XmlSerializer sr = new XmlSerializer(typeof(
MutualSurveyObject));
sr.Serialize(tr,mso_TempObject);
tr.Close();

返回s_RootFileName;

}

catch(例外e)
{
扔e;
}
}
然而,当我尝试执行此操作时,我得到了
以下相当长的异常消息

System.Runtime.Serialization.SerializationExceptio n:
类型FNIS.MutualSurveyApplication.MutualSurveyObject在
程序集MutualSurveyStructureObject中,
Version = 1.0.1411.14253,Culture = neutral,
PublicKeyToken = null未标记为可序列化。

服务器堆栈跟踪:
在System.Runtime.Serialization。 FormatterServices.Int ernalGetS
erializableMembers(RuntimeType type,Boolean
excludeNonSerializable)

S ystem.Runtime.Serialization.FormatterServices.Get Serializa
bleMembers(Type type,StreamingContext context)
在System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitMemberInfo ()
在System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.InitSerialize(Object obj,ISurrogateSelector
surrogateSelector,StreamingContext context,
SerObjectInfoInit serObjectInfoInit ,IFormatterConverter
转换器)
System.Runtime.Serialization.Formatters.Binary.Wri teObjectI
nfo.Serialize(Object obj,ISurrogateSelector
surrogateSelector,StreamingContext context,
SerObjectInfoInit serObjectInfoInit,IFormatterConverter
转换器)
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter
.Serialize(Object graph,Header [] inHeaders,
__BinaryWriter serWriter,Boolean fCheck)
在System.Runtime.Serialization.Formatters.Binary.Bin a ryFormat
ter.Serialize(Stream serializationStream,Object graph,
Header [] headers,Boolean fCheck)
在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)
在System.Runtime.Remoting.Channels.BinaryClientForma tterSink。
SerializeMessage(IMessage msg,ITransportHeaders&标题,
Stream&在/或System.Runtime.Remoting.Channels.BinaryClientForma tterSink。
SyncProcessMessage(IMessage msg)

对象是一个对象是完整的
包含其他对象的集合。这是问题吗?
我迷路了。任何帮助将不胜感激。



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

解决方案

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



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



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



这篇关于将类序列化为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆