Attempted to Read Or Write Protected Memory

I'm using MS Visual Basic 2012
I'm attempting to open an openfiledialog but keep getting an error,
'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
I have tried creating a new form and copied over all the object that were in the form and the code that I've written for the events however that still hasn't worked.

Dim dlgImage As FileDialog = New OpenFileDialog()
dlgImage.Filter = "Image File (*.jpg;*.bmp;*.gif)
If dlgImage.ShowDialog() = DialogResult.OK Then '------ this line through error

The OpenFileDialog class is a standalone class, with its own properties and methods. When you assign the instance to a FileDialog object (the FileDialog class is an ancestor of the OpenFileDialog class, which almost certainly doesn't have all of the same attributes), you are changing the class, and the compiler will attempt to use the attributes of the new class. Change that statement to:

Dim dlgImage As OpenFileDialog = New OpenFileDialog()

Perhaps even more important, your filter definition is incorrect. A filter requires two parts for each selection to appear in the drop list: the first is the text to be displayed in the list, while the second is the actual filter. These two parts are separated by a vertical bar (often called a "pipe") symbol. Your filter should be as follows:

but error is same
and also deleted the ctrl and added again and write all code again the error is same.
in the same project i added a new form and write code again it works there but not on my orignal form

What other controls are on the form?
Do you have any COM controls (AxSomeControl), or references to a COM object in that form?.
I've seen that error numerous times when referencing COM objects from .NET and something doesn't get created / disposed properly.
Rob Lee

What other controls are on the form?
Do you have any COM controls (AxSomeControl), or references to a COM object in that form?.
I've seen that error numerous times when referencing COM objects from .NET and something doesn't get created / disposed properly.
Rob Lee