Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3974
  • Last Modified:

An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

Hi experts
I AM DEVELOPING AN APPLICATION WITH TREEVIEW AND LISTVIEW CONTROLS
 in the tree view control i want to expand the nodes,but when iam expanding the node i am getting a runtime exception An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll.
when i am debugging  i'm getting
AlbumDirectory      Cannot evaluate expression because the current thread is in a stack overflow state.      string  at
  get { return Directory.GetFiles(AlbumDirectory, "*.abm"); }


pls help me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
 
namespace MyAlbumExplorer
{
    internal class AlbumDirectoryNode:TreeNode
    {
        private string  _albumDir;
        public string AlbumDirectory
        {
            get{return _albumDir;}
        }
        public AlbumDirectoryNode(string name, string albumDir)
            : base(name)
        {
            if (albumDir == null)
                throw new ArgumentNullException("albumDir");
            if (!Directory.Exists(albumDir))
                throw new ArgumentException("albumDir is not valid Directory");
            _albumDir = albumDir;
            this.Nodes.Add("chiled");
            this.ImageKey = "AlbumDir";
            this.SelectedImageKey = "AlbumDir";
        }
        public string[] AlbumFiles
        {
            get { return Directory.GetFiles(AlbumDirectory, "*.abm"); }
        }
        private AlbumNode[] _albumNodes = null;
        public AlbumNode[] AlbumNodes
        {
            get
            {
                CreateAlbumNodes();
                return _albumNodes;
            }
        }
 
        public void CreateAlbumNodes()
        {
            String[] files = AlbumFiles;
            int count = files.Length;
            if (_albumNodes == null || AlbumNodes.Length != count)
            {
                Nodes.Clear();
                _albumNodes = new AlbumNode[count];
                for (int i = 0; i < count; i++)
                {
                    string s = files[i];
                    string name = Path.GetFileNameWithoutExtension(s);
                    _albumNodes[i] = new AlbumNode(name, s);
                }
                Nodes.AddRange(_albumNodes);
            }
        }
 
 
    }
}

Open in new window

0
APPIREDDY
Asked:
APPIREDDY
1 Solution
 
pivarCommented:
Hi,

Try changing this line in CreateAlbumNodes()

            if (_albumNodes == null || AlbumNodes.Length != count)
to

            if (_albumNodes == null || _albumNodes.Length != count)


/peter
0
 
sprjp2Commented:
In CreateAlbumNodes() you are referencing AlbumNodes.Length.
AlbumNodes calls CreateAlbumNodes().
This creates infinite recursion which leads to stack overflow.
0
 
APPIREDDYAuthor Commented:
THANK YOU
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now