0

When I use PropertyInfo.SetValue in asp.net , it throws a stackoverflow exception. That I write this code:

    for (int i = 0; i < rivalSeriesIDList.Count; i++)
    {
        cardb_series rivalSeries = seriesBll.GetSeriesInfoByID(rivalSeriesIDList[i].ToString());
        this.GetType().GetProperty("brandid" + (i + 1)).SetValue(this, rivalSeries.brand_id, null);
        this.GetType().GetProperty("seriesid" + (i + 1)).SetValue(this, rivalSeries.series_id, null);
    }

And brandid+number and seriesid+number is a property of aspx_page. like this:

public int brandid1
{
    get
    {
        if (Request.Form["brandid1"] != null)
            return int.Parse(Request.Form["brandid1"]);
        if (Request["brandid1"] != null)
            return int.Parse(Request["brandid1"]);
        return 0;
    }
    set
    {
        brandid1 = value;
    }
}

when I test the code in a Console Application ,It is all right . But when I test it in a Web Application ,it will cause a stack overflow exception . I don't know why. Because of web is no-state? Thanks.

4

1 回答 1

2

cause you call your property recursively, and will get the same exception even if you will call the property directly

public int brandid1 <- this one
{
    get
    {
        if (Request.Form["brandid1"] != null)
            return int.Parse(Request.Form["brandid1"]);
        if (Request["brandid1"] != null)
            return int.Parse(Request["brandid1"]);
        return 0;
    }
    set
    {
       and this one -> brandid1 = value;
    }
}

I don't know what do you want to do, but try this

private int _brandid1;
 public int brandid1 <- this one
    {
        get
        {
            if (Request.Form["brandid1"] != null)
                return int.Parse(Request.Form["brandid1"]);
            if (Request["brandid1"] != null)
                return int.Parse(Request["brandid1"]);
            return 0;
        }
        set
        {
           _brandid1 = value;
        }
    }
于 2009-10-14T05:22:28.397 回答