Error Object reference not set to an instance of an object on webBrowser control
<p>The below code used to work. After fiddling around a while it suddenly stopped working and I receive the following error message.</p>

<p>Error:</p>

<blockquote>
  <p>Object reference not set to an instance of an object.</p>
</blockquote>

<p>Code:</p>

<pre><code>string javascript = @"&lt;script type='text/javascript'&gt;function getUserAgent(){document.write(navigator.userAgent)}&lt;/script&gt;";
webBrowser.Document.Write(javascript);
</code></pre>

<p>C# shows the exception on the webBrowser.Document.Write(javascript) line. webBrowser is just a webBrowser control. I've already tried deleting it and remaking it. Am I missing something silly?</p>
