title: Access Violation Exception in a very small program C#
body: <p>I am making a small program with some <code>textboxes</code> and some <code>labels</code> with a <code>button</code> and a <code>webbrowser</code>. The code is not more than 80 lines and all it contains is a button click event that gives the <code>webbrowser</code> a link entered in the textbox and <code>neviage()</code> function is called and the second event is the browser's document complete event. The error is as follows</p>
  
  <p><img src="https://i.stack.imgur.com/4Vlr4.jpg" alt="enter image description here"></p>
  
  <p>I have googled and searched on stackoverflow about access violation a lot but i was not able to find anything for my purpose. The exception does not occur at any specific point. It comes up randomly and always at <code>Application.Run</code> without any stacktrace!</p>
  
  <p>One thing that is bothering me the most is that the error is occurring in the try block and it is not being caught!</p>
  
  <p>And is there any solution to this exception? I tried going to debug->exceptions->Common Language Runtime Exceptions->System and checking thrown, but it didn't work. </p>
  
  <p>I am a novice programer so forgive my inexperience! </p>
  
  <p>EDIT: Code</p>
  
  <pre><code>public Form1()
          {
              InitializeComponent();
          }
  
          private void simpleButton_Go_Click(object sender, EventArgs e)
          {
              webBrowser1.Navigate(textEdit_url.Text);
              webBrowser1.ScriptErrorsSuppressed = true;
          }
  
          private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
          {
              if (webBrowser1.Url.ToString().Contains("member/login"))
              {
                  if (webBrowser1.Document.GetElementById("email_address")!=null)
                  {                    
                      webBrowser1.Document.GetElementById("email_address").SetAttribute("value", textEdit_username.Text);
                      webBrowser1.Document.GetElementById("member_password").SetAttribute("value", textEdit_password.Text);
  
                      var c = webBrowser1.Document.GetElementsByTagName("button");
                      foreach (HtmlElement element in c)
                      {
                          if (element.InnerText == "Login")
                              element.InvokeMember("click");
                      }
                  }
              }
              if (webBrowser1.Document.GetElementById("toolbar_login") != null &amp;&amp; webBrowser1.Document.GetElementById("toolbar_login").InnerText == "Log In")
              {
                  webBrowser1.Navigate("www.somesite.com");
              }
              else if (webBrowser1.Url.ToString() == textEdit_url.Text)
              {
  
                  var c = webBrowser1.Document.GetElementsByTagName("button");
                  foreach (HtmlElement element in c)
                  {
                      if (element.InnerText == "Add to this list")
                      {
                          element.InvokeMember("click");
  
                          var te = webBrowser1.Document.GetElementsByTagName("textarea");
                      }
                  }
              }
              else
                  webBrowser1.Navigate(textEdit_url.Text);
          }
  </code></pre>
  
  <p>EDIT: Update</p>
  
  <p>As suggested I removed devexpress, made a new winform project, copied the code to that and the error still came. The stacktrace of the new project is</p>
  
  <pre><code> at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
     at System.Windows.Forms.Application.Run(Form mainForm)
     at app.Program.Main() in C:\Documents and Settings\admin\My Documents\Visual Studio 2010\Projects\app\app\Program.cs:line 18
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     at System.Threading.ThreadHelper.ThreadStart()
  </code></pre>