Pin Down Cause of A/V Crash? (Not JIT)

  • Thread starter Thread starter Mahmoud Al-Qudsi
  • Start date Start date
M

Mahmoud Al-Qudsi

I have an application that builds and runs just fine on my PC. It's
pure C#, no P/Invoke, no Win requirements or anything.

I built the app, stuck the dependcies in the same DIR, and copied it
to another PC.
When I run it, it AVs right away, without any details or dialogs. The
event viewer is of no help.

How can I pin down the source of this crash? If it were a JIT error, I
can grab the stack trace and figure it out.... But here?

The other machine has .NET 2.0 installed and has no problem with any
other programs I've written before.

Where do you suggest I start in debugging this?
 
Mahmoud said:
I have an application that builds and runs just fine on my PC. It's
pure C#, no P/Invoke, no Win requirements or anything.

I built the app, stuck the dependcies in the same DIR, and copied it
to another PC.
When I run it, it AVs right away, without any details or dialogs. The
event viewer is of no help.

How can I pin down the source of this crash? If it were a JIT error, I
can grab the stack trace and figure it out.... But here?

The other machine has .NET 2.0 installed and has no problem with any
other programs I've written before.

Where do you suggest I start in debugging this?

Please give a bit more detail as to what you mean by "AV" (I know you mean
access violation), but exactly what is the app doing when it fails? How are
you aware of the failure (message box, app just disappears, etc).

The most likely cause in my experience for an app that just disappears
without any trace is an unhandled exception in a background thread. This
will in fact make an entry in the application event log, but it doesn't tell
you anything very interesting, nor give you any indication that it's related
to your crash, so it's easy to overlook.

One quick thing you could do - add a handler for the AppDomain unhandled
exception event - display the exception in a message box or something simple
and see if you catch anything.

-cd
 
Please give a bit more detail as to what you mean by "AV" (I know you mean
access violation), but exactly what is the app doing when it fails? How are
you aware of the failure (message box, app just disappears, etc).

The most likely cause in my experience for an app that just disappears
without any trace is an unhandled exception in a background thread. This
will in fact make an entry in the application event log, but it doesn't tell
you anything very interesting, nor give you any indication that it's related
to your crash, so it's easy to overlook.

One quick thing you could do - add a handler for the AppDomain unhandled
exception event - display the exception in a message box or something simple
and see if you catch anything.

-cd

Hi Carl,

I get the "this application has encountered an exception"
"Send Report | Don't Send"

It does create a log entry in the Event Viewer, but, as you said,
doesn't contain anything useful.

I'll try adding the AppDomain.UnhandledException handler and see what
it turns up.

Thanks.
-MQ
 
Hi Carl,

I get the "this application has encountered an exception"
"Send Report | Don't Send"

It does create a log entry in the Event Viewer, but, as you said,
doesn't contain anything useful.

I'll try adding the AppDomain.UnhandledException handler and see what
it turns up.

Thanks.
-MQ

Well, I added this code in Main, right before the call to
InitializeComponent:

AppDomain.CurrentDomain.UnhandledException += ErrorHandler.Handler;

And here's the class:

static class ErrorHandler
{
public static void Handler(object sender,
UnhandledExceptionEventArgs args)
{
Exception ex = (Exception)args.ExceptionObject;
Console.WriteLine("Error caught : " + ex.Message);
}
}


Yet it doesn't display my Message Box.....

What else can I do?
I just don't get what's happening... I'm using a couple of 3rd party
dependencies, but they're 100% .NET as well - so if it runs on one
machine with .NET 2.0 installed, shouldn't it run on them all?
 
Mahmoud said:
Well, I added this code in Main, right before the call to
InitializeComponent:

AppDomain.CurrentDomain.UnhandledException += ErrorHandler.Handler;

And here's the class:

static class ErrorHandler
{
public static void Handler(object sender,
UnhandledExceptionEventArgs args)
{
Exception ex = (Exception)args.ExceptionObject;
Console.WriteLine("Error caught : " + ex.Message);
}
}


Yet it doesn't display my Message Box.....

Well, you didn't tell it to display a MessageBox - you wrote the message to
the Console which is, unfortunately, equivalent to dumping it in the
trashcan for a GUI program. You need to use
System.Windows.Forms.MessageBox. Something like this:

public static void Handler(object sender, UnhandledExceptionEventArgs args)
{
Exception ex = (Exception)args.ExceptionObject;
System.Windows.Forms.MessageBox.Show(
string.Format("Unhandled Exception: {0}:{1}\n{2}",
ex.GetType().Name,
ex.Message,
ex.StackTrace
),
"Fatal Application Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
System.Environment.Exit(1);
}

-cd
 
Well, you didn't tell it to display a MessageBox - you wrote the message to
the Console which is, unfortunately, equivalent to dumping it in the
trashcan for a GUI program. You need to use
System.Windows.Forms.MessageBox. Something like this:

public static void Handler(object sender, UnhandledExceptionEventArgs args)
{
Exception ex = (Exception)args.ExceptionObject;
System.Windows.Forms.MessageBox.Show(
string.Format("Unhandled Exception: {0}:{1}\n{2}",
ex.GetType().Name,
ex.Message,
ex.StackTrace
),
"Fatal Application Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
System.Environment.Exit(1);

}

-cd

I actually tried both - no go.
I pasted the wrong code above, I was wondering if since the UI was
never initiliazed if I couldn't try to write it to the console and
catch the output in a debugger, but no go.
 
Back
Top