c# - 如何修复“System.StackOverflowException”?

标签 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;
        }
    }
}

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

An exception of type '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

最佳答案

我的问题现在已经解决了。 解决方案:Increasing the size of the stack

谢谢大家!

关于c# - 如何修复“System.StackOverflowException”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43693858/

相关文章:

wpf - winform/WPF 应用程序的工作示例

c# - List<> 不在 DispatcherTimer 中更新

c# - "Open".net 的 MSMQ

c# - 由于 updatepanel 没有分配窗口 setTimeout?

c# - 适用于带有 C# 绑定(bind)的 Windows 的矢量图形库

wpf - 操作 ObservableCollection 与替换列表

c# - IronPython 在线程中使用 numpy 时抛出 InsufficientMemoryException

c# - Linq OrderBy int 属性不起作用

c# - 快速旋转/变换矩阵乘法

wpf - 如何让WPF中的控件填充可用空间?