title: C# WebBrowser Body is null, GetElementById returns null
body: <p>I am loading a local HTML page using the WebBrowser control.</p>
  
  <pre><code>namespace ConfigEditorWinForms
  {
      [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
      [System.Runtime.InteropServices.ComVisibleAttribute(true)]
      public partial class ConfigEditorForm : Form
      {
          String _currentConfigFilePath = null;
  
  
          public ConfigEditorForm()
          {
              Load += new EventHandler(ConfigEditorForm_Load);
              InitializeComponent();
          }
  
          private void ConfigEditorForm_Load(object sender, EventArgs e)
          {
              webBrowser1.AllowWebBrowserDrop = true;
              webBrowser1.IsWebBrowserContextMenuEnabled = false;
              webBrowser1.WebBrowserShortcutsEnabled = false;
              webBrowser1.ObjectForScripting = this;
            //webBrowser1.ScriptErrorsSuppressed = true;
  
              webBrowser1.DocumentCompleted +=
                  new WebBrowserDocumentCompletedEventHandler(OnDocumentCompleted);
  
              string curDir = Directory.GetCurrentDirectory();
              webBrowser1.Url = new Uri(String.Format("file:///{0}/ConfigEditor/ConfigEditor.html", curDir));
          }
  
          private void OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
          {
              MessageBox.Show("Document completed");
          }
  
          public string GetFileContents(String path)
          {
              return System.IO.File.ReadAllText(path);
          }
  
          public void SaveFileContents(String path, String contents)
          {
              System.IO.File.WriteAllText(path, contents);
          }
  
          private void openToolStripMenuItem_Click(object sender, EventArgs e)
          {
              openFileDialog.InitialDirectory = @"XXX";
              openFileDialog.FilterIndex = 1;
              openFileDialog.RestoreDirectory = false;
  
              if (openFileDialog.ShowDialog() == DialogResult.OK)
              {
                  HtmlDocument doc = webBrowser1.Document;
                  HtmlElement fileToOpenInput = doc.GetElementById("fileToOpenInput");
                  fileToOpenInput.InvokeMember("onchange", new object[1] { openFileDialog.FileName });
                  _currentConfigFilePath = openFileDialog.FileName;
              }
          }
      }
  }
  </code></pre>
  
  <p>On my computer :</p>
  
  <ul>
  <li><p>The document completed event is fired twice</p></li>
  <li><p>Opening a file from the menu works fine too</p></li>
  </ul>
  
  <p>On another computer :</p>
  
  <ul>
  <li><p>The document completed event is only fired (ONCE) when the executable is run as administrator</p></li>
  <li><p>Document.Body is null and Document.GetElementById returns null too, despite the document completed event being fired several seconds before.</p></li>
  </ul>
  
  <p>What's going on please ?</p>
  
  <p>Thank you. :)</p>