This project has moved and is read-only. For the latest updates, please go here.

OutOfMemoryException when set Range.Value2

Jan 3, 2013 at 9:33 PM
Edited Jan 3, 2013 at 9:35 PM

I have 7464 *434 values to set to Range with 7464 rows by 434 columns

XL.Range newDataRange = dataRange.get_Resize(rowCount, colCount);   

newDataRange.Value2 = arr;

I am using the latest NetOffice i.e., thanks

It works sometimes but other times it gives an OutOfMemoryException

It seems randomly and I do not know for sure when the exception will be thrown.

It says "Insufficient memory to continue the execution of the program."

Message: Exception has been thrown by the target of an invocation.

Source: "mscorlib"

Stack Trace:

   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
   at NetOffice.Invoker.PropertySet(COMObject comObject, String name, Object[] value)



Jan 4, 2013 at 6:16 PM

It could be not NetOffice issue but real out of memory. It is not clear from one line of code what your program has done before. Could you give the more context? Have you tried to run similar code in VBA? Perhaps system get out of memory due to repeatedly memory allocation say for resizing Excel ranges. Did your monitor memory consumed by your application (e.g. with Task Manager or Process Explorer)?

Jan 7, 2013 at 4:06 PM
Edited Jan 7, 2013 at 4:44 PM

thanks, artnib.

I monitor memory in task manager and there is still lots of memory available when the exception occurrs.

My code has been like this for a while, I do not know why it starts to have the issue now.

I  am thinking the issue exists before and is discovered just now.

I do resize ranges, but I did dispose after use



Jan 11, 2013 at 7:48 PM

did you have a small example solution for me?
its difficult to help you in very general problem. OutOfMemoryExceptions are the last line in a complex problem most of the time.
7464 *434 is a big thing!!! maybe i can help you to keep the memory usage small and tiny ;)