Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im looking on the other tutorials ang they using the webBrowser1 but on mine it did not show up automatically i already added
using System.Windows.Forms;

if i use the
WebBrowser webBrowser1 = new WebBrowser();
to display the webBrowser1 i having error
n exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll but was not handled in user code

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


What I have tried:

i look on the youtube and i show up right away the
webBrowser1 

can anyone help me thanks in advance
Posted
Updated 17-Dec-17 8:22am
Comments
F-ES Sitecore 17-Dec-17 14:08pm    
Have you googled the error message?
RossMW 17-Dec-17 14:21pm    
Sounds like an issue with your computer / software setup. Try going back to the basics. Can you create a blank project and add a webbrowser object to it with no atatched code and run it? If not, then you have an issue with your environment. If you can run it, then you need to start looking experimenting with basic code to run the webrowser.
Richard Deeming 18-Dec-17 14:47pm    
Find your Main method, and make sure it has the [STAThread] attribute on it.

1 solution

OK, why did you have to add a reference to System.Windows.Forms? This must not be a Windows Forms app to start with and that's probably what's causing this problem. What kind of app did you start with? Console, WPF, ASP.NET, ... ? What?
 
Share this answer
 
Comments
[no name] 17-Dec-17 15:02pm    
"This must not be a Windows Forms app to start with and that's probably what's causing this Problem": Why WebBrowser should not be used in WinForm, I did this more than one time? What I'm missing?
Dave Kreskowiak 17-Dec-17 15:41pm    
Because different project types start with different threading models. Also, things like an ASP.NET project should NEVER use the WebBrowser control.
[no name] 17-Dec-17 15:43pm    
But why you are thinking this is ASP.NET?
Dave Kreskowiak 17-Dec-17 15:56pm    
Because other noobs have attempted it and, in this case, he said he explicitly added the import for System.Windows.Forms.
[no name] 17-Dec-17 15:57pm    
I don't get it, not a big Thing...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900