none
System.Runtime.InteropServices.ComTypes.IDataObject.GetData throws OutOfMemoryException RRS feed

  • Question

  • I have an WinForms application that hosts a WPF window.  I'm occasionally seeing an OutOfMemoryException, not associated with any specific UI action.  I've seen mention of this type of exception associated with the ClipBoard, and indeed looking at the stack trace, I'm seeing ClipBoard methods being called (e.g System.Windows.Clipboard.GetDataObjectInternal()).  The thing is, the stack trace doesn't show any of my code being called, just various Windows libraries (see below).

    My system is:

    CPU: Intel64 Family 6 Model 45 Stepping 7, GenuineIntel
    Operating System: Microsoft Windows 7 Professional
    Is64BitOperatingSystem: True
    OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
    OS Platform: Win32NT
    OS Directory: C:\windows
    Physical Memory (MB): 16307
    Available Memory (MB): 5748
    ProcessorCount: 8
    Is64BitProcess: True

    The stack trace is:

    System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
    at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
    at System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)
    at System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(String format, DVASPECT aspect, Int32 index)
    at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)
    at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)
    at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)
    at System.Windows.Clipboard.IsDataObjectFromLessPriviligedApplicationDomain(IDataObject dataObjectToApply)
    at System.Windows.Clipboard.GetDataObjectInternal()
    at System.Windows.Documents.TextEditorCopyPaste.OnQueryStatusPaste(Object target, CanExecuteRoutedEventArgs args)
    at System.Windows.Input.CommandBinding.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
    at System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
    at System.Windows.Input.CommandManager.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
    at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
    at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
    at System.Windows.Input.RoutedCommand.CanExecuteImpl(Object parameter, IInputElement target, Boolean trusted, Boolean& continueRouting)
    at System.Windows.Input.CommandManager.TransferEvent(IInputElement newSource, CanExecuteRoutedEventArgs e)
    at System.Windows.Input.CommandManager.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)
    at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
    at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
    at System.Windows.Input.RoutedCommand.CanExecuteImpl(Object parameter, IInputElement target, Boolean trusted, Boolean& continueRouting)
    at MS.Internal.Commands.CommandHelpers.CanExecuteCommandSource(ICommandSource commandSource)
    at System.Windows.Controls.Primitives.ButtonBase.UpdateCanExecute()
    at System.Windows.WeakEventManager.ListenerList.DeliverEvent(Listener& listener, Object sender, EventArgs args, Type managerType)
    at System.Windows.WeakEventManager.ListenerList.DeliverEvent(Object sender, EventArgs args, Type managerType)
    at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
    at System.Windows.Input.CommandManager.RaiseRequerySuggested(Object obj)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
    at System.Windows.Threading.DispatcherOperation.InvokeImpl()
    at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Windows.Threading.DispatcherOperation.Invoke()
    at System.Windows.Threading.Dispatcher.ProcessQueue()
    at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
    at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
    at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at CHB.Cardio.EMERIS.Client.Program.Main()

    Tuesday, January 7, 2020 4:21 PM

All replies

  • Hi,

    You can see the following link,it has a similar issue to you.

    https://stackoverflow.com/questions/1213074/winforms-interop-drag-drop-from-winforms-wpf

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 8, 2020 9:44 AM
  • Thanks.  I also saw a post on MSDN about an OOM exception involving a Clipboard method call: "System.Windows.Clipboard.GetDataObject throws OutOfMemoryException" (https://social.msdn.microsoft.com/Forums/vstudio/en-US/6677ee3d-0faf-405b-b7e8-a155a4656c8d/systemwindowsclipboardgetdataobject-throws-outofmemoryexception?forum=wpf)

    Unfortunately, both these cases involved something in the developer source code, i.e. non-serializable classes.  In my case, none my code is being accessed -- all the methods in the stack trace are in system code.  So it's hard to figure out which of my classes, if any, are causing the problem.

    Thursday, January 9, 2020 8:07 PM