0

This is the error I'm getting:

ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.

I have placed the [STAThread] before the ProcessRequest method, but it is still throwing up this error message.

The actual code block is:

// initialize variables
tags = new NameValueCollection();
webBrowser = new WebBrowser();

The error is noted in the new WebBrowser line.

Any ideas on how to get around this error?

djikay
  • 10,450
  • 8
  • 41
  • 52
pithhelmet
  • 2,222
  • 6
  • 35
  • 60
  • [STAThread] is only valid on the Main() entrypoint of a program. Creating your own STA thread requires using Thread.SetApartmentState(). You must also pump a message loop to honor the STA contract, Application.Run(). – Hans Passant Jul 03 '14 at 16:24
  • This is NOT a duplicate - as it applies to a GENERIC HANDLER. – pithhelmet Jul 03 '14 at 19:45
  • @pithhelmet, check this: http://stackoverflow.com/a/22262976/1768303. Note there may be implications with using `WebBrowser` on the server-side, you should prevent any blocking JavaScript UI like `alert`, `confirm` or script errors. – noseratio Jul 04 '14 at 01:43
  • 1
    Noseratio - GREAT post!!!. Thank you I will not be using the webbrowser control... i will use a simple string parser to get around the issue. But thank you for the link!! – pithhelmet Jul 07 '14 at 13:24

0 Answers0