2

I have an application in Win C# 2010,

I have added OpenFileDialog control in my Form.. i have written following code

OpenFileDialog1.ShowDialog();

it throws following Exception :

AccessViolationException:

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

what can be a problem ? and how to solve it?

Thanks..

ghanshyam.mirani
  • 3,075
  • 11
  • 45
  • 85

2 Answers2

2

I found one link, this may help you

http://connect.microsoft.com/VisualStudio/feedback/details/638494/an-accessviolationexception-occurs-when-trying-to-call-the-savefiledialog-method-in-the-closed-event-handler

Another suggestion was disable the AutoUpgrade option or set it to false.

Check this link also Attempted to read or write protected memory

Community
  • 1
  • 1
Anuraj
  • 18,859
  • 7
  • 53
  • 79
1

This would be the correct way:

OpenFileDialog of = new OpenFileDialog();
of.ShowDialog();

EDIT Additionally, this problem may occur in .NET Framework 2.0 Remoting applications on a computer that is running certain types of driver software or antivirus programs.

Source

For testing, please close the antivirus.

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • It depends on how the OP has added the OpenFileDialog component. If the OP added the OpenFileDialog directly in code then this could be the answer, but if the OP used the designer to drag the OpenFileDialog component, then there is another reason for the crash. – Steve Jul 23 '12 at 13:21