0

Possible Duplicate:
Attempted to read or write protected memory. When I call showDialog method of openfileDialog

Not sure why. It was originally working just fine, then I made some changes to the code that should have had no effect on this.

The changes I made where to just change some properties of a checkbox when the file is selected:

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs)
    attachmentLabel.Text = OpenFileDialog1.FileName.ToString()
    attachmentCheckBox.Visible = True
    attachmentCheckBox.Checked = True
End Sub

Here's the event handler that calls OpenFileDialog1.ShowDialog()

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

        OpenFileDialog1.Title = "Please Select a File"
        OpenFileDialog1.InitialDirectory = "C:temp"

        OpenFileDialog1.ShowDialog()


    End Sub

Any help would be appreciated. When the exception occurs, the values for e and sender say "unable to evaluate expression".

Community
  • 1
  • 1
xxyyxx
  • 2,306
  • 3
  • 24
  • 34
  • on what point the error will be thrown? i just tested your code and it works fine on my machine. – John Woo Sep 28 '12 at 01:58
  • It happens shortly after the dialog shows, then when I go to actually try and select a file it just starts to freeze up and then throws the exception. The exact line the exception occurs on is where it says OpenFileDialog1.ShowDialog(). – xxyyxx Sep 28 '12 at 02:27
  • weird because It works fine here. :D do you have any code other than that? – John Woo Sep 28 '12 at 02:38
  • If it really is a stack overflow, only show the part of the stack trace that is not repeating :-) – Mark Hurd Oct 01 '12 at 05:33

1 Answers1

0

(This is really a comment, but it is too big.)
It is due to:

  1. some of your code not shown here,
  2. some filesystem or networking issue specific to your machine, or
  3. a transient problem with VisualStudio (or the VB.NET compiler).

To rule out (3), (and (2) if the problem is transient) reboot your machine and rebuild your application (either clean and then build or at least just rebuild).

To confirm (2), try running your program on a different machine.

To help locate the issue if it is (1), search your code for references to OpenFileDialog1. If it appears anywhere other than in designer generated code and the two events you have shown in your question, include them in your question.

If the problem does still occur, confirm if it occurs with both Debug and Release builds or not, and include the designer generated code in the question as well.

Mark Hurd
  • 10,665
  • 10
  • 68
  • 101