如何解决' System.StackOverflowException?

时间:2017-04-29 09:16:57

标签: c# .net wpf .net-3.5 stack-overflow

我在 WPF 中的 C# NET 3.5 中编写了一个项目,该项目在调试时启动得非常好。但是,例如,在我的TemplateColor.cs课程中,我有这个:

using System;
using System.Windows.Media;

namespace EWIN_THEME_MAKER.ThemeMaker
{
    public class TemplateColor
    {
        private int _id;

        private string _name;

        private string _toneName;

        public int ID
        {
            get
            {
                return this._id;
            }
            set
            {
                this._id = value;
            }
        }

        public int AllVerticalPos
        {
            get;
            set;
        }

        public int AllHorizontalPos
        {
            get;
            set;
        }

        public int HuePageNum
        {
            get;
            set;
        }

        public int HuePos
        {
            get;
            set;
        }

        public int TonePaneNum
        {
            get;
            set;
        }

        public int TonePos
        {
            get;
            set;
        }

        public string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                this._name = value;
                string[] array = this._name.Split(new char[]
                {
                    '_'
                });
                this._toneName = array[0];
                if (array.Length > 1)
                {
                    this.HuePageNum = int.Parse(array[1]);
                }
            }
        }

        public string ToneName
        {
            get
            {
                return this._toneName;
            }
            set
            {
                this._toneName = value;
            }
        }

        public Color DarkColor
        {
            get;
            set;
        }

        public Color MainColor
        {
            get;
            set;
        }

        public Color LightColor
        {
            get;
            set;
        }

        public Color ShadowColor
        {
            get;
            set;
        }

        public byte ShadowA
        {
            get;
            set;
        }

        public Color GrowColor
        {
            get;
            set;
        }

        public Color TextShadowColor
        {
            get;
            set;
        }

        public Color TextMainColor
        {
            get;
            set;
        }

        public Color TextSelectColor
        {
            get;
            set;
        }

        public double TextShadowPosition
        {
            get;
            set;
        }

        public Brush DarkColorBrush
        {
            get
            {
                return new SolidColorBrush(this.DarkColor);
            }
        }

        public Brush MainColorBrush
        {
            get
            {
                return new SolidColorBrush(this.MainColor);
            }
        }

        public Brush LightColorBrush
        {
            get
            {
                return new SolidColorBrush(this.LightColor);
            }
        }

        public Brush ShadowColorBrush
        {
            get
            {
                return new SolidColorBrush(this.ShadowColor);
            }
        }

        public Brush GrowColorBrush
        {
            get
            {
                return new SolidColorBrush(this.GrowColor);
            }
        }

        public Brush TextShadowColorBrush
        {
            get
            {
                return new SolidColorBrush(this.TextShadowColor);
            }
        }

        public Brush TextMainColorBrush
        {
            get
            {
                return new SolidColorBrush(this.TextMainColor);
            }
        }

        public Brush TextSelectColorBrush
        {
            get
            {
                return new SolidColorBrush(this.TextSelectColor);
            }
        }

        public TemplateColor()
        {
            this.ID = -1;
            this.AllVerticalPos = -1;
            this.AllHorizontalPos = -1;
            this.HuePageNum = -1;
            this.HuePos = -1;
            this.TonePaneNum = -1;
            this.TonePos = -1;
            this.Name = "---";
            this.DarkColor = default(Color);
            this.MainColor = default(Color);
            this.LightColor = default(Color);
            this.ShadowColor = default(Color);
            this.ShadowA = 0;
            this.GrowColor = default(Color);
            this.TextShadowColor = default(Color);
            this.TextMainColor = default(Color);
            this.TextSelectColor = default(Color);
            this.TextShadowPosition = 0.0;
        }
    }
}

在此代码中,存在多种此类错误:

  

类型' System.StackOverflowException

的例外

例如,我在那里使用了这部分代码:

public string Name
{
    get
    {
        return this._name;
    }
    set
    {
        this._name = value;
        string[] array = this._name.Split(new char[]
        {
            '_'
        });
        this._toneName = array[0];
        if (array.Length > 1)
        {
            this.HuePageNum = int.Parse(array[1]);
        }
    }
}

那么,在这段代码的下一行中有一个无限的调用?我不知道如何纠正这个错误。

string[] array = this._name.Split(new char[]

和...

this.HuePageNum = int.Parse(array[1]);

我们如何预测和纠正这些错误? Yes

1 个答案:

答案 0 :(得分:0)

我的问题现在已经解决了。 解决方案:使用以下方法增加堆栈的大小: http://content.atalasoft.com/h/i/58213648-increasing-the-size-of-your-stack-net-memory-management-part-3

感谢所有人!