Stack overflow problem --  Help needed

Posted on 2007-07-20
Last Modified: 2013-11-26

  I am working with VB.NET in a windows form.

  I am trying to write a program that loops through several FTP connections. Here is the snippet of code that I am having problems with:

--- Code: ---

                Dim listRequest As FtpWebRequest 'FTP request
                Dim listResponse As FtpWebResponse 'FTP response

                'establishing connection and requesting response
                listRequest = CType(WebRequest.Create(path), FtpWebRequest)
                listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails

                listResponse = CType(listRequest.GetResponse(), FtpWebResponse) 'stack overflow exception is thrown on this line

--- End code ---

This code is looped through when each FTP connection is established. The code works well until about the 1900th loop then i get a stack overflow error thrown.

My question is why am I getting a stack overflow error? I don't see how a stack overflow can occur with the above code.

Exact error message: "An unhandled exception of type 'System.StackOverflowException' occurred in System.dll"

Any help would be appreciated.

Question by:frosty5656
    LVL 9

    Expert Comment

    You need to Dispose and recreate your FTPWeb objects.
    LVL 9

    Expert Comment


    Author Comment

    Thank you for your response.

    How would I go about disposing and recreating the FTPWeb objects?

    I tried:  listResponse.Dispose() and I get an error telling me that Dispose is not a member of System.Net.FTPWebResponse

    Sorry if this question sounds a bit dumb.

    LVL 9

    Accepted Solution

    Could I see the entire loop?

    Also, let's try it without doing the type conversion as it is unnecessary.

                     Dim listRequest As FtpWebRequest 'FTP request
                     Dim listResponse As FtpWebResponse 'FTP response

                    'establishing connection and requesting response
                    listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails

                    listResponse = listRequest.GetResponse()

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now