Giter VIP home page Giter VIP logo

Comments (5)

atifaziz avatar atifaziz commented on August 11, 2024

Do you have a minimal LINQPad script that you can share (even if via LINQPad's Instant Share feature) along with steps that can help to reproduce the problem?

from linqpadless.

rekna1 avatar rekna1 commented on August 11, 2024

Uses System.Windows.Clipboard

void Main()
{
	var text = Clipboard.GetText();
	Console.WriteLine(text);

}

The above compiles but gives the error on running:
Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.

This was the solution I used before:

[STAThread]
static void Main()
{
	var text = Clipboard.GetText();
	Console.WriteLine(text);

}

But compiling gives

 Member 'UserQuery.Main()' cannot be accessed with an instance reference; qualify it with a type name instead
    testrun.cs(24,16): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

from linqpadless.

atifaziz avatar atifaziz commented on August 11, 2024

@rekna1 Thanks for sharing that example. I managed the reproduce the issue.

Meanwhile, a workaround would be to explicitly configure a thread for STA and run your code under that, like this:

void Run()
{
    var text = Clipboard.GetText();
    Console.WriteLine(text);
}

void Main()
{
    var t = new Thread(Run);
    t.SetApartmentState(ApartmentState.STA);
    t.Start();
    t.Join();
}

I've also shared the above query that you can download and try in LINQPad as well as run with LINQPadless.

from linqpadless.

rekna1 avatar rekna1 commented on August 11, 2024

Oké, finally had a chance to try your workaround and that works great !

from linqpadless.

atifaziz avatar atifaziz commented on August 11, 2024

Oké, finally had a chance to try your workaround and that works great !

Good to know and thanks for taking the time to drop in a line to let me know.

from linqpadless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.