title: WinForms: When ObjectForScripting is set, HTML is not displayed
body: <p>I have a Windows forms application and a separate HTML page. The two are supposed to communicate with each other. I followed the instructions from <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.objectforscripting%28v=vs.110%29.aspx" rel="nofollow">this microsoft link</a>. Before I set the ObjectForScripting with <code>WebBrowser.ObjectForScripting = this;</code>, the HTML page displayed correctly. However, after setting <code>ObjectForScripting</code>, the HTML will not display in the WebBrowser component whatsoever. It gives the error "window.external is null or not an object."</p>
  
  <p>C# code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace FirstCSharpApp
  {
      [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
      [System.Runtime.InteropServices.ComVisibleAttribute(true)]
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
              WebBrowser.AllowWebBrowserDrop = false;
              WebBrowser.IsWebBrowserContextMenuEnabled = false;
              WebBrowser.WebBrowserShortcutsEnabled = false;
              WebBrowser.ObjectForScripting = this;
  
              string curDir = Directory.GetCurrentDirectory();
              WebBrowser.Navigate(new Uri(String.Format("file:///{0}/Timeline.html", curDir)));
          }
  
          private void GoButton_Click(object sender, EventArgs e)
          {
              // Works!
              WebBrowser.Document.InvokeScript("test",
                  new String[] { "called from client code" });
          }
  
          private void homeToolStripMenuItem_Click(object sender, EventArgs e)
          {
              WebBrowser.GoHome();
          }
  
          private void goBackToolStripMenuItem_Click(object sender, EventArgs e) 
          {
              WebBrowser.GoBack();
          }
  
          private void goForwardToolStripMenuItem_Click(object sender, EventArgs e)
          {
              WebBrowser.GoForward();
          }
  
          public void Test(String message)
          {
              // Does not work, or apparently even exist
              MessageBox.Show(message, "client code");
          }
      }
  }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script&gt;
          function test(message) {
              alert(message);
          }
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;button onclick ="window.external.Test('called from script')"&gt;
          Call client code.
      &lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>