I have written code for a C# console application. It copies a clipboard value to a file, and it runs without any error.
Now I want to use it in another C# project with other code.
I use [STAThread]
after class{}
, but it give me an error:
:: Attribute 'STAThread' is not valid on this declaration type. It is only valid on 'method' declarations.
What can I do?
You can only put [STAThread]
above the entry point method (not class) and only once in a library. What is your project type that you're trying to copy this code to? Does it even require the STA attribute? Is the method static?
The error is saying you're putting [STAThread]
on something other than an method.
Post up your code.