Consider:
namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent();
I actually got this error because I was checking InnerHtml for some content that was generated dynamically - i.e. a control that is runat=server.
To solve this I had to remove the "static" keyword on my method, and it ran fine.