Click here to Skip to main content
16,005,141 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help with generics Pin
GuimaSun22-Apr-09 9:56
GuimaSun22-Apr-09 9:56 
GeneralRe: Help with generics Pin
Thomas Weller22-Apr-09 20:22
Thomas Weller22-Apr-09 20:22 
GeneralRe: Help with generics Pin
0x3c022-Apr-09 9:30
0x3c022-Apr-09 9:30 
Questionpublically readonly but internally writable objects? Pin
student_rhr22-Apr-09 7:43
student_rhr22-Apr-09 7:43 
AnswerRe: publically readonly but internally writable objects? Pin
harold aptroot22-Apr-09 7:49
harold aptroot22-Apr-09 7:49 
AnswerRe: publically readonly but internally writable objects? Pin
Thomas Weller22-Apr-09 8:33
Thomas Weller22-Apr-09 8:33 
AnswerRe: publically readonly but internally writable objects? Pin
0x3c022-Apr-09 8:36
0x3c022-Apr-09 8:36 
QuestionSerialization and ViewState Pin
Fayu22-Apr-09 7:11
Fayu22-Apr-09 7:11 
I have a class that is serializable (using the SerializableAttribute). I have also implemented the ISerializable to that class. I am able to serialize/deserialize the object by doing the following:

string xml = string.Empty;
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
StringWriter sw = new StringWriter();
settings.OmitXmlDeclaration = true;
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(sw, settings))
{
    XmlSerializer ser = new XmlSerializer(typeof(Content));
    ser.Serialize(writer, this, ns);
    return sw.ToString();
}


My problem is when I try to bind the object to a ViewState, I get the following error:

Type 'System.Xml.XmlNode' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable


Below are my classes (shortened). Any help is appreciated. Thanks in advance.

Content Class:
[Serializable]
[DataObject(true)]
public  class Content : ISerializable
{
  //Constructors
    public Content() { }
    public Content(SerializationInfo info, StreamingContext context)
    {
        this.contentCollection = (List<Content> )info.GetValue("ContentCollection", typeof(List<Content> ));
        this.ContentId = info.GetInt64("ContentId");
        this.Name = info.GetString("Name");
        this.Owner = (Owner)info.GetValue("Owner", typeof(Owner));
    }

  //Properties
    private List<Content> contentCollection;
    [XmlArray("ContentCollection")]
    public List<content> ContentCollection
    {
        get
        {
            if (contentCollection == null) contentCollection = new List<content>();
            return this.contentCollection;
        }
    }

    private System.Int64 contentIdField;
    [XmlAttribute("ContentId")]
    public System.Int64 ContentId
    {
        get { return this.contentIdField; }
        set { this.contentIdField = value; }
    }

    private System.String nameField;
    [XmlElement("Name")]
    public System.String Name
    {
        get { return this.nameField; }
        set { this.nameField = value; }
    }

    private Owner owner;
    [XmlElement("Owner")]
    public Owner Owner
    {
        get { return this.owner; }
        set { this.owner = value; }
    }

    //Deserialization
    #region ISerializable Members
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("ContentCollection", this.ContentCollection);
        info.AddValue("ContentId", this.ContentId);
        info.AddValue("Name", this.Name);
        info.AddValue("Owner", this.Owner);
    }
    #endregion</content></content>


Owner Class:
[Serializable]
[DataObject(true)]
public class Owner : ISerializable
{
    //Constructors
    public Owner() { }
    public Owner(SerializationInfo info, StreamingContext context)
    {
        this.OwnerId = info.GetInt64("OwnerId");
    }

    //Properties
    private long ownerId;
    [Browsable(false)]
    [XmlAttribute("OwnerId")]
    public long OwnerId
    {
        get { return ownerId; }
        set { ownerId = value; }
    }

    #region ISerializable Members
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("OwnerId", this.ownerId);
    }

    #endregion
}

AnswerRe: Serialization and ViewState Pin
Fayu22-Apr-09 7:25
Fayu22-Apr-09 7:25 
GeneralRe: Serialization and ViewState Pin
OriginalGriff22-Apr-09 9:17
mveOriginalGriff22-Apr-09 9:17 
GeneralRe: Serialization and ViewState Pin
Fayu22-Apr-09 9:33
Fayu22-Apr-09 9:33 
GeneralRe: Serialization and ViewState Pin
OriginalGriff22-Apr-09 21:43
mveOriginalGriff22-Apr-09 21:43 
QuestionJust for fun - how slow are exceptions? Pin
Rob Philpott22-Apr-09 6:12
Rob Philpott22-Apr-09 6:12 
AnswerRe: Just for fun - how slow are exceptions? Pin
Eddy Vluggen22-Apr-09 6:24
professionalEddy Vluggen22-Apr-09 6:24 
GeneralRe: Just for fun - how slow are exceptions? Pin
Rob Philpott22-Apr-09 6:38
Rob Philpott22-Apr-09 6:38 
GeneralRe: Just for fun - how slow are exceptions? Pin
Eddy Vluggen22-Apr-09 6:45
professionalEddy Vluggen22-Apr-09 6:45 
GeneralRe: Just for fun - how slow are exceptions? Pin
Luc Pattyn22-Apr-09 6:46
sitebuilderLuc Pattyn22-Apr-09 6:46 
GeneralRe: Just for fun - how slow are exceptions? Pin
Rob Philpott22-Apr-09 6:50
Rob Philpott22-Apr-09 6:50 
GeneralRe: Just for fun - how slow are exceptions? Pin
Luc Pattyn22-Apr-09 6:54
sitebuilderLuc Pattyn22-Apr-09 6:54 
AnswerRe: Just for fun - how slow are exceptions? Pin
Luc Pattyn22-Apr-09 6:31
sitebuilderLuc Pattyn22-Apr-09 6:31 
GeneralRe: Just for fun - how slow are exceptions? Pin
Rob Philpott22-Apr-09 6:33
Rob Philpott22-Apr-09 6:33 
GeneralRe: Just for fun - how slow are exceptions? Pin
Rob Philpott22-Apr-09 6:41
Rob Philpott22-Apr-09 6:41 
GeneralRe: Just for fun - how slow are exceptions? Pin
Skymir23-Apr-09 2:58
Skymir23-Apr-09 2:58 
AnswerRe: Just for fun - how slow are exceptions? Pin
Colin Angus Mackay22-Apr-09 6:36
Colin Angus Mackay22-Apr-09 6:36 
GeneralRe: Just for fun - how slow are exceptions? Pin
Rob Philpott22-Apr-09 6:38
Rob Philpott22-Apr-09 6:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.