开发者

Webdev.Webserver has stopped working

开发者 https://www.devze.com 2022-12-25 19:43 出处:网络
When I execute the code saveXML below it generates the error above, why?? using System; using System.Collections.Generic;

When I execute the code saveXML below it generates the error above, why??

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;
using System.IO;

/// <summary>
/// Summary description for Post
/// </summary>
public class Post
{
    private int postIDCounter = 0;
    private String DateCreated;

    public Post()
    {
        Author = "unknown";
        Title = "unkown";
        Content = "";
        DateCreated = DateTime.Now.ToString();
        ID = postIDCounter++;
    }

    public int ID
    {
        get { return ID; }
        set
        {
            if (ID != value) 
                ID = value;
     开发者_如何学运维   }
    }

    public string Author
    {
        get { return Author; }
        set
        {
            if (Author != value) 
                Author = value;
        }
    }

    public string Title
    {
        get { return Title; }
        set
        {
            if (Title != value)
                Title = value;
        }
    }

    public string Content
    {
        get { return Content; }
        set
        {
            if (Content != value)
                Content = value;
        }
    }

    public void saveXML()
    {
        XmlSerializer serializer = new XmlSerializer(typeof(Post));
        Stream writer  = new FileStream("..'\'App_Data'\'posts'\'" + new Guid(ID.ToString()).ToString() + ".xml", FileMode.Create);
        serializer.Serialize(writer, this);
        writer.Close();
    }
}


All your variables are circular reference, that loops for ever and eventually your system stops / crash.

public string Content
    {
        get { return Content; }

For example, you say here, that get, return the Content, but the return is again the get Content, and get Content, and you understand ? is loop for ever in this line... and in all lines that you have something like that.

Try to do this way.

   string inside_Content;

   public string Content
    {
        get { return inside_Content; }
        set { inside_Content = value;}
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消