title: Winforms, create form instance by form name
body: <p>I need a method that returns a new instance of a form by the name of the form. Here is what I have so far:</p>
  
  <pre><code>    public Form GetFormByName(string frmname)
      {
          return Assembly.GetExecutingAssembly().GetTypes().Where(a =&gt; a.BaseType == typeof(Form) &amp;&amp; 
              a.Name == frmname).Cast&lt;Form&gt;().FirstOrDefault();
      }
  </code></pre>
  
  <p>However I get the following error when I attempt to execute this code:</p>
  
  <p><strong>Unable to cast object of type 'System.RuntimeType' to type 'System.Windows.Forms.Form'.</strong></p>
  
  <p>What does this error mean?</p>