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: