I pasted the sample snippet you provided into the existing sample code, and then built and stepped the console app with an empty command line inside VisualStudio.
As expected, ConsumeMemory threw this First Chance exception:
System.OutOfMemoryException occurred
HResult=-2147024882
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=mscorlib
StackTrace:
at System.IO.MemoryStream..ctor(Int32 capacity)
InnerException:
I carried on stepping from there with [F10], and ConsumeMemory displayed this message:
ConsumeMemory requested 20000 100KB chunks. Allocation failure occurred when idx = 17201
I carried on stepping the code, and the line that constructs the Aspose.Words.Document threw this exception:
System.OutOfMemoryException occurred
HResult=-2147024882
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=Aspose.Words
StackTrace:
at . ..ctor(Int32 )
InnerException:
I carried on stepping and got this exception:
System.TypeInitializationException occurred
HResult=-2146233036
Message=The type initializer for ' ' threw an exception.
Source=Aspose.Words
TypeName=
StackTrace:
at . (Int32 )
at ..ctor(Int32 )
InnerException: System.OutOfMemoryException
HResult=-2147024882
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=Aspose.Words
StackTrace:
at . ..ctor(Int32 )
at ..cctor()
InnerException:
I carried on stepping and got this exception:
System.TypeInitializationException occurred
HResult=-2146233036
Message=The type initializer for 'Aspose.Words.Properties.BuiltInDocumentProperties' threw an exception.
Source=Aspose.Words
TypeName=Aspose.Words.Properties.BuiltInDocumentProperties
StackTrace:
at Aspose.Words.Properties.BuiltInDocumentProperties..ctor()
at Aspose.Words.Document..ctor(Boolean )
InnerException: System.TypeInitializationException
HResult=-2146233036
Message=The type initializer for ' ' threw an exception.
Source=Aspose.Words
TypeName=
StackTrace:
at . (Int32 )
at ..ctor(Int32 )
at ..ctor()
at ..ctor(Boolean )
at Aspose.Words.Properties.BuiltInDocumentProperties..cctor()
InnerException: System.OutOfMemoryException
HResult=-2147024882
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=Aspose.Words
StackTrace:
at . ..ctor(Int32 )
at ..cctor()
InnerException:
When I next pressed [F10] to step the code, execution jumped to the catch block in Program.cs and it dumped those final exception details at the console.
I repeated the debugging steps having put the value 17500 on the command line. This time I got a different exception:
System.OutOfMemoryException occurred
HResult=-2147024882
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=mscorlib
StackTrace:
at System.IO.MemoryStream.set_Capacity(Int32 value)
InnerException:
and when I stepped the code I got this:
occurred
HResult=-2146233088
Message=Cannot extract
Source=Aspose.Words
StackTrace:
at . (String , Stream , String )
InnerException: System.OutOfMemoryException
HResult=-2147024882
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=mscorlib
StackTrace:
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at . (Stream )
at . (String , Stream , String )
InnerException:
This shows the difference between operating when there is no large available memory chunk at all and when there is a very small amount available.