Please share us your code. And on what line you get the error so we could help.
Usually an OutOfMemoryException exception is thrown when an attempt to allocate memory fails. This exception may be thrown with an additional message, "Not enough storage is available to complete this operation," when invoking a method on a COM object that returns a user-defined type that contains a safe array (an array of non-fixed size). This is because the .NET Framework cannot marshal a structure field with a safe array type.
Best links for you:
http://support.microsoft.com/kb/909678[
^]
http://msdn.microsoft.com/en-us/library/9w766t6y(v=vs.80).aspx[
^]
Regards,
Eduard