Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:10:13+00:00 2026-06-10T11:10:13+00:00

Below is some logging output from a .NET application. Error in MainFunction. Message: Exception

  • 0

Below is some logging output from a .NET application.

Error in MainFunction.
Message: Exception of type 'System.OutOfMemoryException' was thrown.
InnerException: 
StackTrace:    at System.Text.StringBuilder.ToString()
   at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Exception.GetStackTrace(Boolean needFileInfo)
   at System.Exception.ToString(Boolean needFileLineInfo)
   at System.Exception.ToString()
   [the rest of the trace is removed]

Which corresponds to the following line of application code. The following is in a catch block, and returns the string to the method that actually throws:

private void MainFunction()
{
   ...

   try
   {
      string doc = CreateXMLDocument(); // <- Out of Memory throws here
   }
   catch (Exception ex)
   {
      CoreLogging("Error in MainFunction.", ex);
   }
}

private string CreateXMLDocument()
{
   try
   {
      //Some basic and well constrained XML document creation:
      ...
   }
   catch (Exception ex)
   {
      return "Exception message: " + ex.ToString();  // <- This is the last line of the trace
   }
}

What should I make of this? Clearly Exception.Message should be used instead of Exception.ToString(), but I’d still like to understand this. Does

  • at System.Text.StringBuilder.ToString()
  • at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)

mean that the stack trace of the exception in CreateXMLDocument was so mammoth caused OutOfMemory? I’m curious to see how that would occur as there’s definitely no circular calls in CreateXMLDocument, which is the only thing I can think of that could cause an enormous stack trace.

Has anyone else encountered a similar situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:10:15+00:00Added an answer on June 10, 2026 at 11:10 am

    I little bit of guessing:

    1) CLR rises a OutOfMemoryException. 2) You catch this exception and call .ToString on it
    3) ToString() tries to allocate memory to the stack trace but… there is no memory and another OutOfMemoryException is rised.

    In the comments you said that the XML documents have a few hundreds of kbytes, this could be a/the problem if your server run on 32bits, because of the fragmentation of the LOH.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is some of my error logging code. When an exception happens inside my
I have a function(please see code below) which reads some data from the web.
// .net 2.0 and vs2005 used. I find some code below. I am not
I have below click_log table logging hits for some urls site ip ua direction
I'm new to powershell, but I'm trying to output some simple logging in a
I'm new to powershell, but I'm trying to output some simple logging in a
I want to run my applet on web application, but i got some error
I am using Quartz.NET for scheduling some custom tasks in our application. Everything works
I came across code written by somebody which caught some exception and tried logging
The Python code below connects to lots of servers, grabs some info from each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.