Dennis Hining
Member
- Joined
- Jun 7, 2021
- Messages
- 12
- Programming Experience
- Beginner
Using Visual Express 2010, I have the following code in a Form Class for the Browse Button (note the Me.OpenFileDialog declaration is in the Class Declaration area.
When running the degugger, I press the Browse Button on the form and get the following error message:
"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. This exception is only raised if a debugger is attached to the process"
I start the program using a main class:
How do I fix the error?????
VB.NET:
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Private Sub but_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_Browse.Click
'**************************************************************************************************
With OpenFileDialog1
.Filter = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*"
.FilterIndex = 1
End With
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
tbox_FileNameMP3.Text = OpenFileDialog1.FileName
Else
tbox_FileNameMP3.Text = ""
End If
End Sub
When running the degugger, I press the Browse Button on the form and get the following error message:
"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. This exception is only raised if a debugger is attached to the process"
I start the program using a main class:
VB.NET:
Public Class Main
<STAThread()> Shared Sub Main()
Dim winForm As Form = New form1
Application.Run(winForm)
End Sub
End Class
How do I fix the error?????
Last edited by a moderator: