开发者

It throws an stackoverflow exception when I user PropertyInfo.SetValue()

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"]);
      开发者_JS百科  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.


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;
        }
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜