tags:

views:

170

answers:

2

I have a rather simple C# program (no UI, just command line) that uses a 3rd party library (Abbyy's Finereader 8.1) to do some work and then exits.

Simple enough and works quite well. Recently however we've started getting the following error from the program:

Application Error : The instruction at "0x2c0de46b" referenced memory at "0x0732aa84".

A little digging shows that this is happening at the end of the C# code. Basically the last two lines are:

  Console.WriteLine(message);
  return statusCode;

The final console message is written and the output from the program is fine. Indeed, if it wasn't for the fact that this error keeps the program from fully terminating I could work around it.

We're running two scripts that invoke this program each on two machines. This happens at random (as far as I can tell) but usually at least one of (the 4 scripts) hits this each day. I thought that perhaps some kind of weirdness was happening for concurrent runs, but testing eliminated that.

Any thoughts on possible causes would be most welcome as I've run out of ideas.

Also if anyone knows of a way to have the program terminate when this happens, that would be useful.

+1  A: 

"Application Error : The instruction at "0x2c0de46b" referenced memory at "0x0732aa84"."

This error implies memory corruption somewhere in your code, without the full code i cannot say more than this. The place where the exception is risen is not important in this case of error. Try to take a look at your code, especially the code that calls the library.

feal87
And did you check for actual faulty memory? I once spent days trying to hunt down an bug which turned out to be an iffy DIMM module...
Onots
This happens on two different machines, purchased about 8 months apart. Hardware failure is improbable.
Kris
This does seem to be what is going on although I've still not been able to isolate the root cause. Fortunately it proved possible to harden the invoking program against this and retrying the command seems to work.
Kris
+1  A: 

Well... Troubleshooting dictates that I ask what changed, but I reckon you thought about that yourself. What version of the .NET framework are you using? What OS(es) does this problem occur on?

I belief that this exception is coming from some cleanup that the 3rd party library does. Did you contact their support? Can you try to explicitly unload the library and see if the error still occurs then?

Or... did you try adding an handler for unhandled exceptions? Might be worth a try...

public static void Main()   
{   
    AppDomain.CurrentDomain.UnhandledException +=   
        new UnhandledExceptionEventHandler(   
            OnUnhandledException);

    //some code here....
}   

/// <summary>
/// Occurs when you have an unhandled exception
/// </summary>
public static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)   
{ 
    //here's how you get the exception  
    Exception exception = (Exception)e.ExceptionObject;  

    //bail out in a tidy way and perform your logging
}

(example code by DoctaJonez)

Just throwing some things out there, since there doesn't seem to be a definite answer (yet).

Onots