473,239 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,239 software developers and data experts.

" 'StackOverflowExcepton' was unhandled " C# Windows App

joedeene
583 512MB
Hello there, I am having a problem and it is frustrating me because I've been trying to figure it out, and I've even modified the code a few times but the same exception occurs: " 'StackOverflowExcepton' was unhandled "

Project Details:

Ok, I am creating a text file that will store database information of some customers of mine and I'm using the StreamReader and StreamWriter Class. I can successfully get the information and customer data written to the file, but when I try to retrieve it and store the retrieved data into the listbox I get that exception. I am using a class library/.DLL also in the project, which shouldn't matter because I can call the AddCustomer() function properly. Here's some of the code...

Expand|Select|Wrap|Line Numbers
  1.  public string[] retrieveCustomers()
  2.         {
  3.             System.IO.StreamReader CustomerStreamReader = new System.IO.StreamReader("MyPath"); //This is the line the error is on
  4.  
  5.             int i = 0;
  6.             string newLine;
  7.             while ((newLine = CustomerStreamReader.ReadLine()) != null)
  8.             {
  9.                 retrieveCustomers().SetValue(newLine, i);
  10.                 i++;
  11.             }
  12.  
  13.             CustomerStreamReader.Close();
  14.  
  15.             return retrieveCustomers();
  16.         }
And I call it from the form's button like this;

Expand|Select|Wrap|Line Numbers
  1.  private void btnReload_Click(object sender, EventArgs e)
  2.         {
  3.             listBoxCustomers.Items.Clear();
  4.             string[] CustomersCollection = papers.retrieveCustomers(); //papers is my .DLL reference.
  5.             foreach (string customerInformation in CustomersCollection)
  6.             {
  7.                 listBoxCustomers.Items.Add(customerInformation);
  8.             }
  9.         }
But there's no error there, Just like to know why it like freezes, and how to fix it. It says "Make sure there is no infinite loop", I don't think I have one though, and it freezes right at the part where I'm declaring the StreamReader in the .DLL

joedeene
Oct 29 '08 #1
8 1729
tlhintoq
3,525 Expert 2GB
Hello there, I am having a problem and it is frustrating me because I've been trying to figure it out, and I've even modified the code a few times but the same exception occurs: " 'StackOverflowExcepton' was unhandled "

Project Details:

Ok, I am creating a text file that will store database information of some customers of mine and I'm using the StreamReader and StreamWriter Class. I can successfully get the information and customer data written to the file, but when I try to retrieve it and store the retrieved data into the listbox I get that exception. I am using a class library/.DLL also in the project, which shouldn't matter because I can call the AddCustomer() function properly. Here's some of the code...

Expand|Select|Wrap|Line Numbers
  1.  public string[] retrieveCustomers()
  2.         {
  3.             System.IO.StreamReader CustomerStreamReader = new System.IO.StreamReader("MyPath"); //This is the line the error is on
  4.  
  5.             int i = 0;
  6.             string newLine;
  7.             while ((newLine = CustomerStreamReader.ReadLine()) != null)
  8.             {
  9.                 retrieveCustomers().SetValue(newLine, i);
  10.                 i++;
  11.             }
  12.  
  13.             CustomerStreamReader.Close();
  14.  
  15.             return retrieveCustomers();
  16.         }
And I call it from the form's button like this;

Expand|Select|Wrap|Line Numbers
  1.  private void btnReload_Click(object sender, EventArgs e)
  2.         {
  3.             listBoxCustomers.Items.Clear();
  4.             string[] CustomersCollection = papers.retrieveCustomers(); //papers is my .DLL reference.
  5.             foreach (string customerInformation in CustomersCollection)
  6.             {
  7.                 listBoxCustomers.Items.Add(customerInformation);
  8.             }
  9.         }
But there's no error there, Just like to know why it like freezes, and how to fix it. It says "Make sure there is no infinite loop", I don't think I have one though, and it freezes right at the part where I'm declaring the StreamReader in the .DLL

joedeene
Have you put breakpoint on line 3 to see if it gets called numerous times? Maybe you really do have a loop.

Try wrapping the guts of the function in a Try {} Catch{} statement. That way you can catch the error and read its message.

Try adding a line for console.writeline("Entered this method"); just above the problem line. If your output window gets slammed with messages then you know you have a loop.


Wait wait wait... Line 15 is calling this function. The return loops back to call itself. Yep, its a loop.
Oct 30 '08 #2
joedeene
583 512MB
Wait wait wait... Line 15 is calling this function. The return loops back to call itself. Yep, its a loop.
So I can't return the function() after it's value has been changed? It only pauses on the streamreader line, and i'll try that try catch statement and get back to you.

joedeene
Oct 30 '08 #3
r035198x
13,262 8TB
...
Wait wait wait... Line 15 is calling this function. The return loops back to call itself. Yep, its a loop.
Line 15 is never reached. The infinite looping is happening on line 9.
Oct 30 '08 #4
Plater
7,872 Expert 4TB
Line 15 is never reached. The infinite looping is happening on line 9.
Line 9 is also a loop.
this smells of a VB programmer trying to learn c#.

Try something like this:
Expand|Select|Wrap|Line Numbers
  1. public string[] retrieveCustomers() 
  2.     List<string> retval = new List<string>();
  3.     System.IO.StreamReader CustomerStreamReader = new System.IO.StreamReader("MyPath"); //This is the line the error is on 
  4.  
  5.     string newLine; 
  6.     while ((newLine = CustomerStreamReader.ReadLine()) != null) 
  7.     { 
  8.         retval.Add(newline);
  9.     } 
  10.     CustomerStreamReader.Close(); 
  11.  
  12.     return retval.ToArray();
  13.  
or
Expand|Select|Wrap|Line Numbers
  1. public string[] retrieveCustomers()
  2. {
  3.   List<string> retval = new List<string>();
  4.   System.IO.StreamReader CustomerStreamReader = new System.IO.StreamReader("MyPath"); //This is the line the error is on  
  5.  
  6.   while (!CustomerStreamReader.EndOfStream)
  7.   {
  8.       retval.Add(CustomerStreamReader.ReadLine());
  9.   }
  10.   CustomerStreamReader.Close();
  11.  
  12.   return retval.ToArray();
  13. }
  14.  
  15.  
Oct 30 '08 #5
r035198x
13,262 8TB
..
this smells of a VB programmer trying to learn c#.

...
<Blocks nose because joe is about to walk in />
Oct 30 '08 #6
joedeene
583 512MB
...this smells of a VB programmer trying to learn c#....
Ya, I did Visual Basic.Net for a while and decided to switch, thanks for the help. I'll try it when i get home :)

joedeene
Oct 30 '08 #7
Plater
7,872 Expert 4TB
this smells of a VB programmer trying to learn c#.
I suppose that came off sounding a bit "mean".
What I ment was, in VB you assign the return value of a function, directly TO the name of the function. so if I had a function called foo() that returned a string, inside the function I would set the return value by saying "foo="some string" (or close to that).
How you were ever able to do recursion in VB, I don't know. In regular languages, referencing the name of the function will CALL the function.
Oct 30 '08 #8
joedeene
583 512MB
I suppose that came off sounding a bit "mean".
What I ment was, in VB you assign teh return value of a function, directly TO the name of the function. so if I had a function called foo() that returned a string, inside the function I would set the return value by saying "foo="some string" (or close to that).
How you were ever able to do recursion in VB, I don't know. In regular languages, referencing the name of the function will CALL the function.
Nah, I didn't take it mean, iA said a while back that VB had/teaches lazy habits and I guess that's one of them, but ya I haven't worked with functions much in c# since VB but ya it does make sense that it calls that 'referencing the name of the function will CALL the function'. But it vb you could say something like that, well thanks for the knowledge, I'm home and I'm gonna try the above code now...

Edit: Yay it works, thanks a whole bunch, now I can continue with my database...

joedeene
Oct 30 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
1
by: Chris | last post by:
I built small C# Web and Web Service applications in a training class last week. The applications worked in the class, but when I tried to run them again over the weekend, they both bombed....
2
by: thorax | last post by:
I'm having problems running a release build of an application. The application is a native C++ .NET 2003 MFC application which links to a number of other DLLs, one of which is mixed (SLGSE.dll)...
11
by: TheBurgerMan | last post by:
Hi all. I am using W2K3, .NET2 on a machine running AD and Exchange. I started getting the message below last week. I googled the error and not much was returned, but I did find this;...
2
by: eBob.com | last post by:
I've got the basics of an XML ini file working. I.E. I can stash away and retrieve user preferences. (Code below.) But how do I handle a new preference? Say I have A and B. And then I invent...
1
by: Samuel R. Neff | last post by:
Occasionally we get this error message when running an app on a test machine: .exe - Common Language Runtime Debugging Services Application has generated an exception that could not be...
9
by: MrSpock | last post by:
1. Create a new Windows Application project. 2. Open the project properties and check "Make single instance application". 3. Build. 4. Go to the release folder and run the application. 5. Try to...
0
by: ilangovan | last post by:
Hai friends, I have a problem in my windows application which contains about 11000 lines. For this application, i download the tabcontrols from the net. An error which has the name of...
7
by: j4richard | last post by:
Help please, I am getting this "Unhandled Exception has occurred in your application" " A Generic error occurred in GDI+" See the end of this message for details on...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.