[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Stack overflow problem -- Help needed

Hello:

  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.

Thanks.
0
frosty5656
Asked:
frosty5656
  • 3
1 Solution
 
traxionCommented:
You need to Dispose and recreate your FTPWeb objects.
0
 
traxionCommented:
listResponse.Dispose()
0
 
frosty5656Author Commented:
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.

0
 
traxionCommented:
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.Create(path)
                listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails

                listResponse = listRequest.GetResponse()
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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