473,320 Members | 2,071 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,320 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 1738
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.