We have a standard textbox in a Winforms application which responds to paste (both right-click menu and CTRL+V) in the normal way (ie it pastes) in our dev environment.
At one customer site the paste is mostly completely ignored (behaves as if there's nothing in the clipboard). We've tested it with both single line and multiline versions of the TextBox and we've created a standalone app with just a couple of TextBoxes and on this one client site the problem persists. Pasting mostly doesn't work.
In further testing we find that simply asking for the clipboard's content within a test winforms app, it comes back as empty string. Double checking with Notepad we find there's definitely something in the clipboard.
Here's what we've checked:
Remember that the very same compiled application always pastes successfully on our dev machines and does occasionally paste successfully on the customer's machines! This is what makes it so mysterious.
In all cases we've verified that there is something in the clipboard by pasting into Notepad alongside our app.
Has anyone else has seen this and/or can suggest an explanation?
Update/Further investigation
Could it be that it's something to do with threading? We don't do anything interesting with threading and we've never had to worry about using an STAThread attribute. But the MSDN page says:
The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.
So, in a Winforms project with no main thread - just a startup form, where do you put this attribute? And why don't we need it on the dev machines? And how come we've never needed to use it on any of countless other Winforms apps we've made?
I have a fancy firewall that is also able block applications from looking at data in the clipboard, on per-application basis.
It does not prevent writing; the point of the feature is to stop malware from stealing important information that might end up in the clipboad, such as a password.
It can also block any given application from doing various other system tasks, e.g. taking a screenshot or navigating to a web page with the default system browser.
The customer might have something like that installed, with Notepad allowed in the rules.