Hi all,

I have the following code for returning an ArrayList from a function:

Code:
        public ArrayList listFilesAndFolders(Uri uriLevel)
        {
            StreamReader reader = null;
            ArrayList alFilesAndFolders = new ArrayList();

            if (uriLevel.Scheme != Uri.UriSchemeFtp)
            {
                return null;
            }

            try
            {
                FtpWebRequest listRequest = (FtpWebRequest)WebRequest.Create(getFTPPath(uriLevel.ToString()));
                listRequest.Method = WebRequestMethods.Ftp.ListDirectory;
                //listRequest.Credentials = new NetworkCredential(m_username, m_password);
                listRequest.Credentials = m_networkcred;

                FtpWebResponse listResponse = (FtpWebResponse)listRequest.GetResponse();
                
                reader = new StreamReader(listResponse.GetResponseStream());

                while (!reader.EndOfStream)
                {
                    alFilesAndFolders.Add(reader.ReadLine());
                }

                listResponse.Close();
            }
            catch (UriFormatException ex)
            {
                Debug.Print(ex.Message);
                return null;
            }
            catch (WebException ex)
            {
                Debug.Print(ex.Message);
                return null;
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

            return alFilesAndFolders;
        }
I keep getting an error after the loop has been run through that reader has thrown an exception: System.ObjectDisposedException and it is caught by the code which calls the function. In the watch window when debugging it also confirms the exception is thrown. I cannnot see why the reader is disposed prior to me actually closing it. Can somebody please help and provide any suggestions.

Many thanks in advance,

Grant