سؤال

I was trying to connect to web browser control but it continuously threw exception that iwebbrowser2 should implement iwebbrowser2 something like this ,then i googled and found solution to this ,chose com objects then from there microsoft web browser after chosing i got control to apply on form and i did.

next wrote code

var t = new Thread(() =>
{
    Form1 frm1 = new Form1();

    //new FormDialogWatcher(frm1.Handle);
    Settings.AutoStartDialogWatcher = false;
    var ie = new IE( frm1.WebBrowser1);

    ie.GoTo("http://www.google.com");
});
t.SetApartmentState(ApartmentState.STA);
t.Start();

as other threads at stack overflow suggest.added reference introp.SHdocve but when i build 68 errors occured:

Error 64

Cannot embed interop type 'SHDocVw.tagREADYSTATE' found in both assembly 'e:\XMLreader\lib\Interop.SHDocVw.dll' and 'e:\XMLreader\XMLreader\obj\x86\Debug\Interop.SHDocVw.dll'. onsider setting the 'Embed Interop Types' property to false.

I right clicked at this dll and changed embed interop to false but with no effect.

I commented out var ie = new IE( frm1.WebBrowser1);and all 68 errors were gone.

هل كانت مفيدة؟

المحلول

Why do you want the Form at all. Try this:

var ie = new IE();

The ApartmentState can be set for the whole application within the config as well.

<configuration>
  <configSections>
    <sectionGroup name="NUnit">
      <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
  </configSections>

  <NUnit>
    <TestRunner>
      <!-- Valid values are STA,MTA. Others ignored. -->
      <add key="ApartmentState" value="STA" />
    </TestRunner>
  </NUnit>


</configuration>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top