尝试读取或写入受保护的内存。当我调用 openfileDialog 的 showDialog 方法时
最近在我的项目中,当我调用 OpenFileDialog
的 ShowDialog
方法时,我收到此错误:
“尝试读取或写入受保护的内存。这通常表明其他内存已损坏。 ”
我之前一直在网上搜索,但我的问题没有解决。 我还安装了微软补丁,但因为我的项目是.Net 3.5,所以没有用。
代码示例:
OpenFileDialog OFD = new OpenFileDialog();
OFD.ShowDialog();
感谢您的帮助。
recently in my project when I call ShowDialog
method of OpenFileDialog
I get this error:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I have been searching all over the web before now but my problem did not solve.
Also I installed microsoft patch, but because my project is in .Net 3.5, it was not useful.
Code Sample:
OpenFileDialog OFD = new OpenFileDialog();
OFD.ShowDialog();
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
OpenFileDialog 将大量非托管代码加载到您的进程中。您计算机上安装的所有 shell 扩展。其中之一对您的流程环境不太满意,或者对您的流程造成足够的混乱,导致其崩溃和烧毁。
您需要找到导致此问题的 shell 扩展。从“项目+属性”开始,“调试”选项卡,勾选“启用非托管代码调试”选项。现在,您将在“输出”窗口中看到加载的 DLL 列表。在获得例外之前你看到的最后一个人很可能就是麻烦制造者。尽管您仍然需要将 DLL 名称逆向工程为 shell 扩展名称。
另一种方法是刀耕火种。使用 SysInternals 的 AutoRuns 实用程序。单击“资源管理器”选项卡并禁用所有非 Microsoft 制作的内容。请访问 superuser.com 询问更多相关问题
OpenFileDialog loads a large amount of unmanaged code into your process. All of the shell extensions that you have installed on your machine. One of them isn't very happy about your process environment, or messes with your process enough to make it crash and burn.
You'll need to find the shell extension that causes this. Start with Project + Properties, Debug tab, tick the "Enable unmanaged code debugging" option. You'll now see the list of DLLs that get loaded in the Output window. Odds are reasonable that the last one you see before you get the exception is the trouble-maker. Although you'll still have to reverse-engineer the DLL name to the shell extension name.
The other approach is slash and burn. Use SysInternals' AutoRuns utility. Click the Explorer tab and disable anything that wasn't made by Microsoft. Ask more questions about this at superuser.com
这解决了我的问题。在连接字符串中添加
OLE DB Services=-1
然后其工作。像这样:
或者如此链接所示
This is solved my problem. In Connection string add the
OLE DB Services=-1
then its working.Like this:
Or as shown in this link
我也有这个问题。
我使用 OpenFileDialog 选择一个 Excel 文件,然后使用 .net Oledb 读取数据并将数据写入 Access 数据库。
第一次:确定
第二次,选择文件后,出现此消息:尝试读取或写入受保护的内存
我的解决方案:
带有 OpenFileDialog 的表单“A”和一个用于显示和选择文件的按钮,并且:
openFileDialog1.ReadOnlyChecked = true;
openFileDialog1.ShowReadOnly = true;
形式“B”
使用 get/set 设置要读取的文件名
一种读取excel文件并写入Access db的方法。
从“A”,发送文件名读取到“B”形式
加载“B”表单,执行主流程,查看结果并关闭表单
返回“A”时,我可以选择另一个文件并重复该过程,不会出现错误
不再出现“尝试读取或写入受保护的内存”错误
我不知道这是否是最佳解决方案,但应用程序运行良好。
问候
I had this problem too.
I was using OpenFileDialog to select an Excel file, then read the data with .net Oledb and write data to Access database.
The first time: OK
The second time, after select file, appeared this message: Attempted to read or write protected memory
My solution:
A form "A" with an OpenFileDialog and a button to display and select files and:
openFileDialog1.ReadOnlyChecked = true;
openFileDialog1.ShowReadOnly = true;
A form "B"
With a get/set to set the filename to read
A method to read excel file and write to Access db.
From "A", send filename to read to "B" form
Load "B" form, execute the main process, view results and close form
On return "A", I could select another file and repeat the process without errors
No more "Attempted to read or write protected memory" error
I don't know if it's the best solution but the application runs well.
Greetings