title: Current thread must be set to single thread apartment in VB.NET
body: <p>This is the <code>new</code> method in my form:</p>
  
  <pre><code>Public Sub New(ByVal ConnectionString As String, ByVal ConSql As SqlClient.SqlConnection, ByVal Daman As Array, ByVal SDate As Integer, ByVal FDate As Integer)
  
      Threading.Thread.CurrentThread.TrySetApartmentState(Threading.ApartmentState.STA)
      ' This call is required by the Windows Form Designer.
      'Error Appear in this line
      InitializeComponent()
  
      ' Add any initialization after the InitializeComponent() call.
      Me.Sto_TypeFormFrameTableAdapter.Connection.ConnectionString = ConnectionString
      Me.Sto_typeformTableAdapter.Connection.ConnectionString = ConnectionString
      con = ConSql
      com.Connection = con
      ConNew = ConnectionString
      DamaneCod = Daman
      Start = SDate
      Final = FDate
      Fill()
  End Sub
  </code></pre>
  
  <p>When I create a new object of my form, the <code>InitializeComponent</code> command gets an error.</p>
  
  <p>The error message is:</p>
  
  <blockquote>
    <p>Current thread must be set to single thread apartment (STA) mode
    before OLE calls can be made. Ensure that your Main function has
    STAThreadAttribute marked on it.</p>
  </blockquote>
  
  <p>This form is in a project whose output is a DLL file for another project, and the error does not appear in another project that used this DLL file.
  How can I fix it?</p>