Possible Duplicate:
Attempted to read or write protected memory. When I call showDialog method of openfileDialog
My project was created in winxp and now migrated to windows7. I am getting a weird exception while click on the openfiledialog icon in my project and the application crashes after this. This only happens when I create a release build and install that build in windows 7.
The setup is also created in the windows 7. I do no get this exception when run the code in the debug mode.
I am setting the initialdirectory property of the openfiledialog to desktopdirectory.
Below is the exception trace i caught in the windows event viewer.
Application: projectname.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at System.Windows.Forms.UnsafeNativeMethods.GetOpenFileName(OPENFILENAME_I)
at System.Windows.Forms.OpenFileDialog.RunFileDialog(OPENFILENAME_I)
at System.Windows.Forms.FileDialog.RunDialogOld(IntPtr)
at System.Windows.Forms.FileDialog.RunDialog(IntPtr)
at System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window)
at System.Windows.Forms.CommonDialog.ShowDialog()
at companyname.projectname.MainForm.processFileOperation(FileOperationType)
at companyname.projectname.MainForm.fileOpenMenuItem_Click(System.Object, System.EventArgs)
at companyname.projectname.MainForm.toolBar_ButtonClick(System.Object, System.Windows.Forms.ToolBarButtonClickEventArgs)
at System.Windows.Forms.ToolBar.OnButtonClick(System.Windows.Forms.ToolBarButtonClickEventArgs)
at System.Windows.Forms.ToolBar.WmReflectCommand(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ToolBar.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(System.Runtime.InteropServices.HandleRef, Int32, IntPtr, IntPtr)
at System.Windows.Forms.Control.SendMessage(Int32, IntPtr, IntPtr)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr, System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.WmCommand(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ScrollableControl.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Form.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
at System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.DefWndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control.WmMouseUp(System.Windows.Forms.Message ByRef, System.Windows.Forms.MouseButtons, Int32)
at System.Windows.Forms.Control.WndProc
(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.ToolBar.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
at System.Windows.Forms.Application
+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
at System.Windows.Forms.Application.Run(System.Windows.Forms.Form)
at companyname.projectname.MainForm.Main(System.String[])