GemBox Support Forum

System.OutOfMemoryException when calling ExcelFile.Save(String, SaveOptions)

I am intermittently getting the following error:

Unable to invoke method Save on class - Exception has been thrown by the target of an invocation.,Exception: Exception has been thrown by the target of an invocation.,Inner Exception: Exception of type ‘System.OutOfMemoryException’ was thrown.

when attempting to save an Excel file (xlsx file format) using GemBox.Spreadsheet 4.3. Are there common causes for this exception to be thrown or any documentation on the condition(s) that would cause this exception to be thrown?

Hi Daniel,

Can you create a small Visual Studio project for us that will reproduce your issue so that we can investigate it?

The only thing that comes to my mind is that an OutOfMemoryException would occur in case you have a very large spreadsheet and your application runs out of memory.

For more information about this, check the Performance example:

The more cells you have, the more memory you’ll need. The amount of data you can handle depends on a few factors, like the machine’s available memory, the application’s architecture (32-bit or 64-bit), the targeted .NET platform (.NET Framework or .NET Core), etc.

However, this doesn’t seem to be your case because this exception should occur consistently, not intermittently as you mentioned.


Hi Mario,

Thank you for your response. I was able to resolve the issue. I was simply allocating memory for some .NET objects and not freeing them causing a memory leak. Please consider this issue closed.