StackOverflow Exception

Help
2010-06-05
2013-01-26
  • Hi,

    I am creating merged PDF files from existing documents, and sometimes I get a StackOverflow exception when calling PageManager.Add(Document document) method. I am using C# .NET 3.5. Here is my code snippet:

                    ArrayList sourceFiles = new ArrayList();

                    //store PDF file paths in sourceFiles
                    ……
                    files::File file = new files::File();
                    Document targetDocument = file.Document;
                    PageManager pm = new PageManager(targetDocument);

                    for (int i = 0; i < sourceFiles.Count; i++)
                    {
                        string pdfFile = (string)sourceFiles_;
                        files::File sourceFile = new files::File(pdfFile);
                        pm.Add(sourceFile.Document); //the line where StackOverflowException occurs
                    }

                    Serialize(file, targetDocPath);

    Is there any way to work around the exception?

    Thanks!_

     
  • Hi,

    the only way to work around this exception is to fix its bug :-)

    Could you please post its stack trace (this way maybe I can spot the issue - there seems to be an infinite recursion somewhere…)?

    You may also try to debug directly from its source code: that's quite a simple task - catch the StackOverflowException from your IDE and walk back through its stack.

     
  • Hi,

    Thanks for replying!

    Can't catch the stack overflow exception in .NET 2.0 or later, and the only detail I get when the error pops up is this: {Cannot evaluate expression because the current thread is in a stack overflow state.} Is there something else I could try?