Failed to set WinForms clipboard in unit test

I would like to fill out Forms.Clipboard form with text from the NUnit test.

The first problem I ran into was that the clipboard should be used in STA mode. I found a solution (NUnit 2.5.x +) to set the RequiresSTA attribute in the method.

Next, I get an ExternalException when I call Clipboard.SetText (). I found a solution to use Clipboard.SetDataObject (object, bool, int, int), where you can specify retryTimes to make several attempts to set the clipboard. This hacker solution sometimes works, which is clearly not enough (increasing the retryTimes parameter, of course, also increases the likelihood of success).

Others (like Peter ) have succeeded in doing this, so maybe this has something to do with my environment: I am running VS2010 under 64-bit targeting of Windows 7.NET 3.5 and x86. NUnit version is 2.5.9.

I am stuck. Any help would be appreciated.

+3
source share
1 answer

Answering my own question:

As suggested by Hans Passant in the comments, the problem was that another process was interfering. The evil process seems to be Google Chrome.

0
source

All Articles