I'm getting a stack overflow exception for a segment of code that doesn't seem to be able to produce a stackoverflow... It looks like this:
public String WriteToFile(XmlDocument pDoc, String pPath)
{
string source = "";
string seq = "";
string sourcenet = "";
XmlNodelist sourceNode = pDoc.GetElementsByTagName(XmlUtils.Nodes.Source);
source = sourceNode.Item(0).InnerText;
XmlNodelist sqList= pDoc.GetElementsByTagName(XmlUtils.Nodes.Seq);
seq = sqList.Item(0).InnerText;
XmlNodelist sourceNets = pDoc.GetElementsByTagName(XmlUtils.Nodes.SourceNets);
sourcenet = sourceNets.Item(0).InnerText;
string fileName = Folders.GetMyFileName(source, seq, sourcenet);
string fullPath = Path.Combine(pPath, fileName);
pDoc.Save(pFullPathFile); <--- Stackoverflow is raised here
return pFullPathFile;
}
There are no recursive calls, if you examine the call stack it has a depth of 2 before going to "external code" (which I'm guessing is not that external but part of the framework that starts the thread, which has debugging turn off).
¿Is there anyway the exception can be risen because anything other than a recursive call? It does ALWAYS fails in the pDoc.Save method call... and pDoc isn't actually that big... more like 32KB of data...
The most-common cause of stack overflow is excessively deep or infinite recursion, in which a function calls itself so many times that the space needed to store the variables and information associated with each call is more than can fit on the stack. An example of infinite recursion in C.
If a program uses more memory space than the stack size then stack overflow will occur and can result in a program crash. If function recursively call itself infinite times then the stack is unable to store large number of local variables used by every function call and will result in overflow of stack.
A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been allocated to that stack.
In recursion, the new function call will be created in stack memory section. If our recursive function doesn't have any base case or the recursive function call doesn't align towards the base case, it will keep on create function calls in the stack memory section.
A stack overflow exception can occur any time that the stack exceeds it's maximum size. This is mostly commonly done with by ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With