Hello I am getting an error on the following line:
If Not System.Windows.Clipboard.GetDataObject Is Nothing Then
I believe it would look something like this in C#
if (System.Windows.Clipboard.GetDataObject!=null) {
The Error is:
“ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.”
Can anyone tell me how to fix this? A few suggestions online mentioned adding <STAThread()> _ over the ‘main’ method, however, this is an ASP.NET controller method, I tried adding this over it and it didn’t help. Anyone have any suggestions?
ASP.NET doesn’t really get along with STAThread.
You need an additional task scheduler to run a thread in STA mode to access what you want from the operating system
Take a look at this article it got me going with something like this.
Also, keep in mind that multiple request to your page might mess up things, since you’re interacting with the clipboard of the operating system (which runs in another COM context) son concurrency might by risky.
What are you trying to acomplish, maybe there is a better way.