1

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.

wulfgarpro
  • 6,666
  • 12
  • 69
  • 110
  • 1
    The bug is somewhere in your interaction with the external API. There's not much advice I can give with the information you've presented besides making sure you're not passing the API any null references. – Gabe May 09 '11 at 04:43
  • 1
    @Gabe - checked for null references - not the problem. I'm starting to think it has to do with my interfacing with the third-party application via out-of-proc COM. – wulfgarpro May 09 '11 at 05:12
  • An `AccessViolationException` cannot happen with purely managed code, so the problem has to be in interfacing with your 3rd-party app. – Gabe May 09 '11 at 05:19
  • Out-of-proc COM sounds like a very likely candidate for this error. I'd start by checking whenever you call any COM methods and make sure the parameters passed are correct – Orion Edwards Nov 09 '11 at 21:11

2 Answers2

2

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.

IAmTimCorey
  • 16,412
  • 5
  • 39
  • 75
0

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.

iheanyi
  • 3,107
  • 2
  • 23
  • 22