0

I have a few problem with the Windows Clipboard in my WPF desktop application. I try to retrieve clipboard content, do something (without write on this content, only read), and re-send the content into clipboard. It run, but after re-send the content, if I retrieve clipboard content and try to read again, I have an OutOfMemory exception.

After search, I've found this link : http://www.grumpydev.com/2009/09/05/system-outofmemoryexception-gotcha-using-clipboard-getdata-in-wpf/

It's maybe because of a serialization problem, I think that my data loose his serialisation attribut or else when I send it into the clipboard.

Here is my code :

var data = System.Windows.Clipboard.GetDataObject();
// Read "data"
System.Windows.Clipboard.Clear();
System.Windows.Clipboard.SetDataObject(data, true);

var dataTwo = System.Windows.Clipboard.GetDataObject();
// Read "dataTwo" ==> OutOfMemoryException

Notice that the data has not a Type of my project, it can be everything (photoshop, excel, picture, text, binary...)

Anyone has an idea to correct this?

Thank you un advance

Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
Veler
  • 161
  • 2
  • 13

1 Answers1

0

Based on the link you mentioned and conclusions in there, it looks as if the data variable type must be marked as [Serrializable].

As you need it to be pretty much "everything" you can try using an interface ISerializable

class Foo
{
    private ISerrialisable data;
    ...
}

So as long as the object is serrializable you should be able to use it with clipboard.

oleksii
  • 35,458
  • 16
  • 93
  • 163
  • Hi, Thank you for your answer. I've tried what you said, but it strange, I have and MDA Excpetion, based on the code of this thread : http://stackoverflow.com/questions/1213074/winforms-interop-drag-drop-from-winforms-wpf Maybe I forgot somthing ? – Veler Aug 09 '13 at 14:51
  • Anyone have an idea? I'm blocked – Veler Aug 10 '13 at 07:06