C# WinForms 异常:“System.AccessViolationException”类型的第一次机会异常
我有一个基本的 WinForms 应用程序。我正在调用外部 API,该 API 生成以下异常:
尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
UavController.exe 中发生了“System.AccessViolationException”类型的第一次机会异常
调用如下所示:
outputBroker.SelectedObjectPaths .AddWithID(((AgAircraft)aircraft).Path, ((AgAircraft)aircraft).InstanceName);
我找不到任何问题的迹象。
I have a basic WinForms application. I'm making a call to an external API which is generating the following exception:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
A first chance exception of type 'System.AccessViolationException' occurred in UavController.exe
The call looks like this:
outputBroker.SelectedObjectPaths.AddWithID(((AgAircraft)aircraft).Path, ((AgAircraft)aircraft).InstanceName);
I can't find any indication of the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该问题是由您的 API 生成的。您通过调用向 API 传递了错误数据,或者您的 API 本身存在问题。如果您有权访问 API 代码,以下 Microsoft 链接可能会对您有所帮助:
http://msdn.microsoft.com/en-us/library/ms164911(v=vs.80).aspx
否则,我认为您可能需要使用您的 API提供商找出问题是什么以及如何解决它。
The issue is one generated by your API. Either you are passing in bad data to the API through your call or your API has an issue on its own. Here is a Microsoft link that might help you if you have access to the code of your API:
http://msdn.microsoft.com/en-us/library/ms164911(v=vs.80).aspx
Otherwise, I think you might need to work with your API provider to figure out what the issue is and how to resolve it.
第一次机会异常并不总是错误。第一次机会异常是您正在调试的代码第一次引发异常。如果您的代码处理了异常,那么这一切的作用就是通知您发生了异常。
例如,我可能有代码尝试查找具有特定名称的文件,如果找到,则执行某些操作。如果文件名不存在,则会引发异常,我会处理该异常并采取其他操作。因此,尽管发生了异常,但它是预期的行为并由代码处理。
如果您收到第二次机会异常通知,则意味着您的代码实际上并未处理引发的异常。那时,您想看看发生了什么。您只是再次重新抛出异常以供更高级别的代码捕获,还是完全忽略它。
A first chance exception isn't always a bug. A first chance exception is the first time an exception was thrown by code that you are debugging. If your code handles the exception, then all this serves to do is notify you that an exception occurred.
For example, I may have code that attempts to find a file with a specific name and if found, does certain things. If the file name doesn't exist, an exception is throw, which I handle and take other action. So, though an exception occurs, it is expected behavior and handled by code.
If you're having second chance exception notifications, this means that your code doesn't actually handle the exception that was thrown. At that point, you'd want to look at what's going on. Are you just re-throwing the exception again for higher level code to capture or are you ignoring it altogether.