XMLSerialization Framework version 2.0.40607

L

Lee Alexander

hi,

Perhaps someone can help me. I am trying to serialize an object but the
serialization isn't working. I have created a small console app to show my
problem. Perhaps someone with more knowledge could nudge me in the correct
direction.

Regards
Lee

#region Using directives

using System;

using System.Collections.Generic;

using System.Xml.Serialization;

#endregion

namespace TestSerialization

{

public class Employee

{

public Employee()

{

}

public Employee( string name )

{

this.Name = name;

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

private string _name = string.Empty;

}

public class Work

{

public Work()

{

}

public EmployeeCollection Employees

{

get

{

return _employees;

}

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

public class EmployeeCollection: ICollection<Employee>

{

#region ICollection<Employee> Members

public void Add( Employee item )

{

_employees.Add( item );

}

public void Clear()

{

_employees.Clear();

}

public bool Contains( Employee item )

{

return _employees.Contains( item );

}

public void CopyTo( Employee[] array, int arrayIndex )

{

_employees.CopyTo( array, arrayIndex );

}

public int Count

{

get { return _employees.Count; }

}

public bool IsReadOnly

{

get { return false; }

}



public bool Remove( Employee item )

{

return _employees.Remove( item );

}

#endregion

#region IEnumerable<Employee> Members

IEnumerator<Employee> IEnumerable<Employee>.GetEnumerator()

{

return _employees.GetEnumerator();

}

#endregion

private List<Employee> _employees = new List<Employee>();

}

private EmployeeCollection _employees = new EmployeeCollection();

private string _name = string.Empty;

}

class Program

{

private static string DumpException( Exception ex )

{

string info = string.Empty;

do

{

info += WriteExceptionInfo( ex );

ex = ex.InnerException;

} while( ex != null );

return info;

}

private static string WriteExceptionInfo( Exception ex )

{

string info = string.Empty;

info += string.Format( "--------- Exception Data ---------" ) +
Environment.NewLine;

info += string.Format( "Exception Type: {0}", ex.GetType().FullName ) +
Environment.NewLine;

info += string.Format( "Message: {0}", ex.Message );

return info;

}

static void Main( string[] args )

{

try

{

Work work = new Work();

work.Name = "SomePlace";

work.Employees.Add( new Employee( "Lee" ) );

work.Employees.Add( new Employee( "Stuart" ) );

XmlSerializer s = new XmlSerializer( typeof( Work ) );

s.Serialize( Console.Out, work );

}

catch( Exception e )

{

Console.WriteLine( DumpException( e ) );

}

Console.Read();

}

}

}
 
W

Willy Denoyette [MVP]

Please post this to a Whidbey NG, the NG is for the release version of
CSharp.
Note that the 40607 is an old version of v2.0 beta1, the XML serialization
has changed a bit since then, I suggest you don't waste your time with this
version download the november or december CTP instead or wait for beta2.

Willy.

Lee Alexander said:
hi,

Perhaps someone can help me. I am trying to serialize an object but the
serialization isn't working. I have created a small console app to show my
problem. Perhaps someone with more knowledge could nudge me in the correct
direction.

Regards
Lee

#region Using directives

using System;

using System.Collections.Generic;

using System.Xml.Serialization;

#endregion

namespace TestSerialization

{

public class Employee

{

public Employee()

{

}

public Employee( string name )

{

this.Name = name;

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

private string _name = string.Empty;

}

public class Work

{

public Work()

{

}

public EmployeeCollection Employees

{

get

{

return _employees;

}

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

public class EmployeeCollection: ICollection<Employee>

{

#region ICollection<Employee> Members

public void Add( Employee item )

{

_employees.Add( item );

}

public void Clear()

{

_employees.Clear();

}

public bool Contains( Employee item )

{

return _employees.Contains( item );

}

public void CopyTo( Employee[] array, int arrayIndex )

{

_employees.CopyTo( array, arrayIndex );

}

public int Count

{

get { return _employees.Count; }

}

public bool IsReadOnly

{

get { return false; }

}



public bool Remove( Employee item )

{

return _employees.Remove( item );

}

#endregion

#region IEnumerable<Employee> Members

IEnumerator<Employee> IEnumerable<Employee>.GetEnumerator()

{

return _employees.GetEnumerator();

}

#endregion

private List<Employee> _employees = new List<Employee>();

}

private EmployeeCollection _employees = new EmployeeCollection();

private string _name = string.Empty;

}

class Program

{

private static string DumpException( Exception ex )

{

string info = string.Empty;

do

{

info += WriteExceptionInfo( ex );

ex = ex.InnerException;

} while( ex != null );

return info;

}

private static string WriteExceptionInfo( Exception ex )

{

string info = string.Empty;

info += string.Format( "--------- Exception Data ---------" ) +
Environment.NewLine;

info += string.Format( "Exception Type: {0}", ex.GetType().FullName ) +
Environment.NewLine;

info += string.Format( "Message: {0}", ex.Message );

return info;

}

static void Main( string[] args )

{

try

{

Work work = new Work();

work.Name = "SomePlace";

work.Employees.Add( new Employee( "Lee" ) );

work.Employees.Add( new Employee( "Stuart" ) );

XmlSerializer s = new XmlSerializer( typeof( Work ) );

s.Serialize( Console.Out, work );

}

catch( Exception e )

{

Console.WriteLine( DumpException( e ) );

}

Console.Read();

}

}

}
 
L

Lee Alexander

Willy,

Thanks for the heads up. I'll post where you said and also look into
downloading the latest bits.

Cheers
Lee
Willy Denoyette said:
Please post this to a Whidbey NG, the NG is for the release version of
CSharp.
Note that the 40607 is an old version of v2.0 beta1, the XML serialization
has changed a bit since then, I suggest you don't waste your time with
this version download the november or december CTP instead or wait for
beta2.

Willy.

Lee Alexander said:
hi,

Perhaps someone can help me. I am trying to serialize an object but the
serialization isn't working. I have created a small console app to show
my problem. Perhaps someone with more knowledge could nudge me in the
correct direction.

Regards
Lee

#region Using directives

using System;

using System.Collections.Generic;

using System.Xml.Serialization;

#endregion

namespace TestSerialization

{

public class Employee

{

public Employee()

{

}

public Employee( string name )

{

this.Name = name;

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

private string _name = string.Empty;

}

public class Work

{

public Work()

{

}

public EmployeeCollection Employees

{

get

{

return _employees;

}

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

public class EmployeeCollection: ICollection<Employee>

{

#region ICollection<Employee> Members

public void Add( Employee item )

{

_employees.Add( item );

}

public void Clear()

{

_employees.Clear();

}

public bool Contains( Employee item )

{

return _employees.Contains( item );

}

public void CopyTo( Employee[] array, int arrayIndex )

{

_employees.CopyTo( array, arrayIndex );

}

public int Count

{

get { return _employees.Count; }

}

public bool IsReadOnly

{

get { return false; }

}



public bool Remove( Employee item )

{

return _employees.Remove( item );

}

#endregion

#region IEnumerable<Employee> Members

IEnumerator<Employee> IEnumerable<Employee>.GetEnumerator()

{

return _employees.GetEnumerator();

}

#endregion

private List<Employee> _employees = new List<Employee>();

}

private EmployeeCollection _employees = new EmployeeCollection();

private string _name = string.Empty;

}

class Program

{

private static string DumpException( Exception ex )

{

string info = string.Empty;

do

{

info += WriteExceptionInfo( ex );

ex = ex.InnerException;

} while( ex != null );

return info;

}

private static string WriteExceptionInfo( Exception ex )

{

string info = string.Empty;

info += string.Format( "--------- Exception Data ---------" ) +
Environment.NewLine;

info += string.Format( "Exception Type: {0}", ex.GetType().FullName ) +
Environment.NewLine;

info += string.Format( "Message: {0}", ex.Message );

return info;

}

static void Main( string[] args )

{

try

{

Work work = new Work();

work.Name = "SomePlace";

work.Employees.Add( new Employee( "Lee" ) );

work.Employees.Add( new Employee( "Stuart" ) );

XmlSerializer s = new XmlSerializer( typeof( Work ) );

s.Serialize( Console.Out, work );

}

catch( Exception e )

{

Console.WriteLine( DumpException( e ) );

}

Console.Read();

}

}

}
 
L

Lee Alexander

hmm I can't seem to find the Whidbey group, is it on a different server?

Regards
Lee

Lee Alexander said:
Willy,

Thanks for the heads up. I'll post where you said and also look into
downloading the latest bits.

Cheers
Lee
Willy Denoyette said:
Please post this to a Whidbey NG, the NG is for the release version of
CSharp.
Note that the 40607 is an old version of v2.0 beta1, the XML
serialization has changed a bit since then, I suggest you don't waste
your time with this version download the november or december CTP instead
or wait for beta2.

Willy.

Lee Alexander said:
hi,

Perhaps someone can help me. I am trying to serialize an object but the
serialization isn't working. I have created a small console app to show
my problem. Perhaps someone with more knowledge could nudge me in the
correct direction.

Regards
Lee

#region Using directives

using System;

using System.Collections.Generic;

using System.Xml.Serialization;

#endregion

namespace TestSerialization

{

public class Employee

{

public Employee()

{

}

public Employee( string name )

{

this.Name = name;

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

private string _name = string.Empty;

}

public class Work

{

public Work()

{

}

public EmployeeCollection Employees

{

get

{

return _employees;

}

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

public class EmployeeCollection: ICollection<Employee>

{

#region ICollection<Employee> Members

public void Add( Employee item )

{

_employees.Add( item );

}

public void Clear()

{

_employees.Clear();

}

public bool Contains( Employee item )

{

return _employees.Contains( item );

}

public void CopyTo( Employee[] array, int arrayIndex )

{

_employees.CopyTo( array, arrayIndex );

}

public int Count

{

get { return _employees.Count; }

}

public bool IsReadOnly

{

get { return false; }

}



public bool Remove( Employee item )

{

return _employees.Remove( item );

}

#endregion

#region IEnumerable<Employee> Members

IEnumerator<Employee> IEnumerable<Employee>.GetEnumerator()

{

return _employees.GetEnumerator();

}

#endregion

private List<Employee> _employees = new List<Employee>();

}

private EmployeeCollection _employees = new EmployeeCollection();

private string _name = string.Empty;

}

class Program

{

private static string DumpException( Exception ex )

{

string info = string.Empty;

do

{

info += WriteExceptionInfo( ex );

ex = ex.InnerException;

} while( ex != null );

return info;

}

private static string WriteExceptionInfo( Exception ex )

{

string info = string.Empty;

info += string.Format( "--------- Exception Data ---------" ) +
Environment.NewLine;

info += string.Format( "Exception Type: {0}", ex.GetType().FullName ) +
Environment.NewLine;

info += string.Format( "Message: {0}", ex.Message );

return info;

}

static void Main( string[] args )

{

try

{

Work work = new Work();

work.Name = "SomePlace";

work.Employees.Add( new Employee( "Lee" ) );

work.Employees.Add( new Employee( "Stuart" ) );

XmlSerializer s = new XmlSerializer( typeof( Work ) );

s.Serialize( Console.Out, work );

}

catch( Exception e )

{

Console.WriteLine( DumpException( e ) );

}

Console.Read();

}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top