Hello,

I have a list of objects that I want to serialize as XML and save it as
user setting. The objects are of type of the following class.

[Serializable]
public class SourceFolder
{
public SourceFolder(string path, bool controlled, bool
includesSub)
{
this.path = path;
this.controlled = controlled;
this.includesSub = includesSub;
}

public string Path
{
get
{
return path;
}
set
{
path = value;
}
}

public bool Controlled
{
get
{
return controlled;
}
set
{
controlled = value;
}
}

public bool IncludesSub
{
get
{
return includesSub;
}
set
{
includesSub = value;
}
}

private string path;
private bool controlled;
private bool includesSub;
}

In my settings object, I have a property of type List<SourceFolder>
that I assign my object list before saving. Unfortunately, the only
output in the file user.config is the following:

<setting name="SourceFolders" serializeAs="Xml">
<value />
</setting>

When I add the attribute
SettingsSerializeAs(SettingsSerializeAs.Binary) to the settings
property, it works, but the list is serialized binary what I do not
want.

Visual Studio 2005 help states that .NET framework is able to serialize
lists of any object to XML stream. What am I doing wrong that it does
not work for me? When I use List<string> instead of List<SourceFolder>,
it works fine, but not with my class.


Regards, Jens

Re: Serialize List of objects as XML by sloan

sloan
Wed May 10 12:47:45 CDT 2006


I have some 1.1 code at:
http://spaces.msn.com/sholliday/ 9/21/2005

I haven't done anything with 2.0 and generics.

Maybe it can help, maybe not.




"Jarod" <jarod@onlinehome.de> wrote in message
news:1147277067.169713.293270@i39g2000cwa.googlegroups.com...
> Hello,
>
> I have a list of objects that I want to serialize as XML and save it as
> user setting. The objects are of type of the following class.
>
> [Serializable]
> public class SourceFolder
> {
> public SourceFolder(string path, bool controlled, bool
> includesSub)
> {
> this.path = path;
> this.controlled = controlled;
> this.includesSub = includesSub;
> }
>
> public string Path
> {
> get
> {
> return path;
> }
> set
> {
> path = value;
> }
> }
>
> public bool Controlled
> {
> get
> {
> return controlled;
> }
> set
> {
> controlled = value;
> }
> }
>
> public bool IncludesSub
> {
> get
> {
> return includesSub;
> }
> set
> {
> includesSub = value;
> }
> }
>
> private string path;
> private bool controlled;
> private bool includesSub;
> }
>
> In my settings object, I have a property of type List<SourceFolder>
> that I assign my object list before saving. Unfortunately, the only
> output in the file user.config is the following:
>
> <setting name="SourceFolders" serializeAs="Xml">
> <value />
> </setting>
>
> When I add the attribute
> SettingsSerializeAs(SettingsSerializeAs.Binary) to the settings
> property, it works, but the list is serialized binary what I do not
> want.
>
> Visual Studio 2005 help states that .NET framework is able to serialize
> lists of any object to XML stream. What am I doing wrong that it does
> not work for me? When I use List<string> instead of List<SourceFolder>,
> it works fine, but not with my class.
>
>
> Regards, Jens
>



Re: Serialize List of objects as XML by Jarod

Jarod
Thu May 11 10:39:44 CDT 2006

Hello,

In the meantime I have solved the problem. I made a wrapper class
SourceFolderList which contains the List<SourceFolder>. Additionally I
had to assign the attribute XmlInclude(typeof(SourceFolder)) to this
class and now it works fine.


Jens