Click here to Skip to main content
15,946,525 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone

I have a VB2010 .Net program which maintains Supplier details. Each supplier has a certificate (PDF). The Supplier Maintenance program has a button which is intended to open a File dialog box, allow the user to select a PDF file and the program then stores the path and file name.

Private Sub but_Certificate_Path_Click(sender As System.Object, e As System.EventArgs) Handles but_Certificate_Path.Click
    Dim ofd As New OpenFileDialog

    ofd.Filter = "PDF Files(*.pdf)|*.pdf|All files (*.*)|*.*"

    ofd.FilterIndex = 1
    ofd.InitialDirectory = "\\xxx\BEE"

    If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then  '<--CRASH OCCURS HERE
        txt_Bee_Certificate_Path.Text = ofd.FileName
    End If

End Sub

When the 'Path' button is clicked the program crashes with :
Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.

I am not using the OpenFileDialog1 control.

The Call Stack info that I am able to find is :
SupplierMaintenance.exe!SupplierMaintenance.frm_Supplier_Maint.but_Certificate_Path_Click(Object sender, System.EventArgs e) Line 415 Basic
[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]
[External Code]

Do I have a coding problem or a problem with user32.dll?

Does anyone know how I can resolve this - I am absolutely clueless.

Many thanks
Richard MacCutchan 4-Dec-13 6:48am    
Are you sure that initial directory path is valid?
Darrell de Wet 4-Dec-13 7:24am    
Yes. I just changed it to xxx for this post. xxx = File server name.
Richard MacCutchan 4-Dec-13 8:06am    
All I can suggest is that you step through the code with your debugger and try to find out what is happening.
Fredrik Bornander 4-Dec-13 8:33am    
Create a new WinForms application with a single button that has the payload of the above OnClick handler to verify that it is not an environment issue.
If that application does not crash then it's something that your application has done to it's memory before calling that method.

Are you PInvoking anything?
Are you using unsafe code?
Darrell de Wet 5-Dec-13 2:36am    
Hi Fredrik - thanks for your response.
I hope that I am not using any unsafe code - what would unsafe code be?
I am relatively new to .Net so I can do with all the assistance I can get

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900