0

I have done a good amount of research on this "problem". My site does not use recursion except for later in the program but the part I'm debugging has not gotten to that yet so that cannot be the issue. Visual studio does not like this page of mine. In order to debug the page, I have to usually first debug another page before it by viewing the values of a few variables. If I try to start debugging the page without first debugging another page, a box will popup in visual studio. I have pasted this image also. It's the 2nd image showing the same large negative integer value. There are about 100 calls throughout the code to this function below. Can a stackoverflow occur just because these are alot of calls to the same function ?

Protected Function Calcpmtafterio(ByVal maxbal As Decimal, ByVal npmts As Int16, ByVal starttype As Int16, ByVal startrate As Decimal, ByVal startper As Int16, ByVal pmtcap As Decimal, ByVal pmtper As Int16, ByVal orate As Decimal, ByVal nrate As Decimal, ByVal obal As Decimal, ByVal tpmts As Int16, ByVal io As Int16, ByVal iocb As Boolean, ByVal miamt As Decimal) As Decimal



 Payment = Calcpmtafterio(maxbalance, numpmts, pmtinit, pmtadj1, pmtadj1mo1, pmtadjcap, pmtadjper, Origrate, Noterate, Origbal, TotPmts, Io, cbioinitialperiod.Checked, miamt)

I think it is blowing up because of the size of the page. The page has about 16800 lines of code. It has been working fine for me until I added more code blocks. My code is an amortization calculator and there are 9 rows and each row has identical code blocks. One computes the payments and the other section is the looping section which determines when to exit the loop and start a new row with a new payment.

I have watched a video showing the diagnostic tools which has a memory usage tab and shows the heap size and the Call Stack. I don't see any information about what is causing the error. When I drill down into the error underlined in green in my vs, there is a negative number which is quite large probably too large for an integer. What can cause this to happen in visual studio?

enter image description here

enter image description here

dbc
  • 104,963
  • 20
  • 228
  • 340
Scot
  • 29
  • 4
  • Hello! Add a tag with the language you're using. Is it Visual Basic? – Marc Le Bihan Jul 01 '23 at 01:12
  • Hi Marc, yes it is. – Scot Jul 01 '23 at 02:17
  • 1
    Please don't add images of code. Please provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) which others can use to re-create the issue that you're facing. – Tu deschizi eu inchid Jul 01 '23 at 02:50
  • One thing I did notice is that you are checking if a database connection is open. This is unnecessary, because the connection should be disposed of after every use which means the connection will never be open. The easiest way to ensure that an object is disposed, is to use a [using statement](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/using-statement). – Tu deschizi eu inchid Jul 01 '23 at 02:56
  • The following may be helpful: https://stackoverflow.com/a/68355687/10024425 and https://stackoverflow.com/a/70321177/10024425 – Tu deschizi eu inchid Jul 01 '23 at 03:01
  • #1) the image is not of my code. That's Visual studios internal code. The image is there because it's not possible to copy and paste that information #2 ) it's not possible to provide a mimimal reproducible example. What part of 16000 lines of code do you not understand? No one will be able to reproduce my issue. I need someone to do a live share on my computer. Are there any takers who are familiar with Stack Overflow exceptions? – Scot Jul 01 '23 at 14:53
  • I have a couple of functions and I was using the same variable names in the delegate as I do in the main program where the call comes from. I tried changing the names in my delegate to be unique variables from the call. In making this change, the Stack overflow still happens. – Scot Jul 01 '23 at 15:32
  • 1
    _it's not possible to provide a mimimal reproducible example_: While, it may feel like this is true, rest assured that I wouldn't have asked you to perform an impossible task. – Tu deschizi eu inchid Jul 01 '23 at 16:07
  • 1
    The code is calling the function Calcpmtafterio inside Function Calcpmtafterio. You probably meant to actually do the calculation in the function. Or are you just showing the function signature and an example of calling it? – Andrew Morton Jul 01 '23 at 17:27
  • *Can a stackoverflow occur just because these are alot of calls to the same function ?* -- no. See [this answer](https://stackoverflow.com/a/30336304) by Eric Lippert to [How is a StackOverflowException detected?](https://stackoverflow.com/q/30327674) for how Windows detects a stack overflow. More likely you have some unexpected or unintended recursion somewhere that is overflowing the stack such as [How to prevent StackOverflowException when reusing a callback in a callback?](https://stackoverflow.com/q/29125460). – dbc Jul 01 '23 at 17:28
  • 2
    "The page has about 16800 lines of code" - you should break it up into several files of classes of methods grouped together meaningfully. Otherwise, debugging and maintenance will be unnecessarily difficult. – Andrew Morton Jul 01 '23 at 17:33
  • 1
    Also, might you please [edit] your question to include the errors, stack trace and the most relevant bits of your code as **text** rather than as screenshots -- even if the code is external code? It's requested here not to to use images for this purpose, see [*Why should I not upload images of code/data/errors?*](https://meta.stackoverflow.com/a/285557) for why. – dbc Jul 01 '23 at 17:34
  • to Andrew. Yes, I'm just showing a call from outside the function. Also, debugging was not an issue until recently. This purpose of writing this function is to eliminate putting the same code blocks into each of the 10 sections. – Scot Jul 02 '23 at 01:05
  • How can I find out where the "unintended recursion" is in my code? – Scot Jul 02 '23 at 01:09
  • [How to debug a stackoverflowexception in .NET](https://stackoverflow.com/q/4733878) and [How to find the source of a StackOverflowException in my application](https://stackoverflow.com/q/18721841) might help. Or you could add calls like `Debug.Assert(new System.Diagnostics.StackTrace().FrameCount < 64 /* Or whatever max depth you want */)` around where you think the recursion may be happening, and break on the assert. – dbc Jul 02 '23 at 21:42
  • 2
    "The page has about 16800 lines of code." You've managed to create a maintenance nightmare for yourself. If you were me, you'd start over from scratch and build the thing using TDD. Your code will naturally flow into nicely grouped and modular classes/methods. Otherwise, you're only continuing to pile on technical debt. It's a bitter pill to swallow, yes, but the longer you wait the more bitter it becomes. Your current problem appears to be a direct outgrowth of a deeply monolithic code base. – InteXX Jul 04 '23 at 09:59
  • I took a backup of my program which did not have this issue. I have moved a portion of the code into a functions page which I'm now importing at the top. So far it is working in debug mode, although after I change the code it takes about 10 seconds to reprocess it and highlight my break point. Often it just logs me out and I have to restart but that is better than getting the Stack overflow error. This has stopped occurring for now but the second debugging image does appear sometimes. When this happens I close the solution and restart the program. This usually clears its brain. – Scot Jul 05 '23 at 12:58

0 Answers0