473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

crash in release build

The application i build in C#.net is crashing once a month. I can't
reproduce the crash.

Is there a way to track down where the program crashes, without
putting logging everywhere in the code? Is there a way to get a stack
trace of the crashing program (by the way, i'm new to C#.net, i have
experience in (unmanaged) C++).

Thanks in advance.

Feb 7 '07 #1
6 4776
Sure it is the application? As in: it could be defective RAM on where the
application is used. I had that :-)

<bj*****@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
The application i build in C#.net is crashing once a month. I can't
reproduce the crash.

Is there a way to track down where the program crashes, without
putting logging everywhere in the code? Is there a way to get a stack
trace of the crashing program (by the way, i'm new to C#.net, i have
experience in (unmanaged) C++).

Thanks in advance.
Feb 7 '07 #2
Is there a way to track down where the program crashes, without
putting logging everywhere in the code? Is there a way to get a stack
trace of the crashing program (by the way, i'm new to C#.net, i have
experience in (unmanaged) C++).
If you want information about a crash, you're going to need to implement
some form of logging. If I understand you correctly, you want to limit the
points where you implement logging. So, the most likely point is in the
application run loop. This would be found in your Main method, and is
usually found in the statement

Application.Run(...)

If you put a try/catch block around that, you can implement logging at that
level. Unhandled exceptions will bubble up to the application level. If you
want a stack trace, you can certainly put it into your log at this point,
but the proximity of the exception to the application level may limit the
amount of stack data you receive at that point. This is found in the
StackTrace property of the Exception.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.
<bj*****@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
The application i build in C#.net is crashing once a month. I can't
reproduce the crash.

Is there a way to track down where the program crashes, without
putting logging everywhere in the code? Is there a way to get a stack
trace of the crashing program (by the way, i'm new to C#.net, i have
experience in (unmanaged) C++).

Thanks in advance.

Feb 7 '07 #3
Hi,
If you don't have any idea where it's crashing (like the call stack),
you might want to consider implementing a centralized unhandled
exception handler.

// Add the event handler for handling UI thread exceptions to the
event.
System.Windows.Forms.Application.ThreadException += new
ThreadExceptionEventHandler(Application_ThreadExce ption);
// Set the unhandled exception mode to force all Windows Forms errors
to go through our handler.
System.Windows.Forms.Application.SetUnhandledExcep tionMode(UnhandledExceptionMode.CatchException);
// Add the event handler for handling non-UI thread exceptions to the
event.
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);

Then in the exception handlers, you can get the stack, for example:

private static void Application_ThreadException(object sender,
ThreadExceptionEventArgs e)
{
// e.Exception.StackTrace will contain the call stack where
the exception occurred, write it to a file or something....
...
}

If that's not helping very much, you could try to use a tool like
ADPlus to grab a crash dump of the process and use Windbg with the SOS
extension to look at the state of the program at the time of the
crash. That's more work though.

Hope that helps,
John

On Feb 7, 7:19 am, bjor...@gmail.com wrote:
The application i build in C#.net is crashing once a month. I can't
reproduce the crash.

Is there a way to track down where the program crashes, without
putting logging everywhere in the code? Is there a way to get a stack
trace of the crashing program (by the way, i'm new to C#.net, i have
experience in (unmanaged) C++).

Thanks in advance.

Feb 7 '07 #4
On 7 Feb 2007 04:19:06 -0800, bj*****@gmail.com wrote:
>The application i build in C#.net is crashing once a month. I can't
reproduce the crash.

Is there a way to track down where the program crashes, without
putting logging everywhere in the code? Is there a way to get a stack
trace of the crashing program (by the way, i'm new to C#.net, i have
experience in (unmanaged) C++).

Thanks in advance.
Why do you not want to use logging?

If you mean you don't want to log to the Event Viewer, then log to a file ONLY
WHEN AN EXCEPTION IS THROWN. There's no point in logging successful completion
of a run. When you log the exception log the stack trace by writing the stack
trace to the file by calling TheException.ToString(); or
TheException.StackTrace();

of course you will need to surround your code with try/catch blocks. You are
using try/catch blocks aren't you?

You don't need to put logging everywhere in the code if you make your catch like
this:

catch
{
throw;
}

When you do this you should put another try/catch block in an appropriate
location that is complete like this:

catch(Exception ex)
{
WriteToYourLog(ex.ToString();
}

All exceptions will be bubbled up to the final handler where they are logged.

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
Feb 7 '07 #5
Hi,

Don't underestimate the power of instrumentation! (cheesy, I know)

Seriously, let's say you use everyone's suggestions to get the exception
logged, which is a great idea to begin with. Now, how do you debug it?
Sure, you may have the call stack and the exception but you'll probably have
no idea about the application's *state* at the time of the crash. With
tracing to the Application event log you will.

Just add calls to Trace.WriteLine in places where the state of the
application changes frequently and supply a short message and the values of
some of the local variables and fields. You can do the same in your
exception handling code as well, which should be used sparingly in most
applications.

Before the application starts (a good place is the Main method of your
program, before the call to Application.Run), add a call to:

System.Diagnostics.Trace.Listeners.Add(
new System.Diagnostics.EventLogTraceListener(Applicati on.ProductName));

All of your trace output will be logged to the Application event log with
your app's name as the event source.

If you use a global TraceSwitch in your application then you can easily turn
on/off tracing (and, therefore, the event log output) using the app.config
file. If a user reports crashes or strange behavior you can ask them to
turn on tracing for you and send you the event log if the error occurs
again.

// assuming traceSwitch is an instance of the TraceSwitch class:
if (traceSwitch.TraceVerbose)
Trace.TraceInformation("Updated stock from {0} to {1}", stockOld,
stockNew);

TraceSwitch Class
http://msdn2.microsoft.com/en-us/lib...aceswitch.aspx

I like to use the Program class created by VS 2005 to encapsulate a global
switch:

public static class Program
{
private static readonly TraceSwitch traceSwitch =
new TraceSwitch("Global",
Application.ProductName + " Trace Switch");

[Conditional("TRACE")]
public static void TraceVerbose(string format, params object[] args)
{
if (traceSwitch.TraceVerbose)
Trace.TraceInformation(format, args);
}

[Conditional("TRACE")]
public static void TraceVerbose(string message)
{
if (traceSwitch.TraceVerbose)
Trace.TraceInformation(message);
}
}

You can then use something like the following throughout your code:

Program.TraceVerbose("Updated stock from {0} to {1}", stockOld, stockNew);

--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in Visual Studio 2005)

<bj*****@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
The application i build in C#.net is crashing once a month. I can't
reproduce the crash.

Is there a way to track down where the program crashes, without
putting logging everywhere in the code? Is there a way to get a stack
trace of the crashing program (by the way, i'm new to C#.net, i have
experience in (unmanaged) C++).

Thanks in advance.

Feb 7 '07 #6
There sure is a good way to do it.

The first thing you want to do is make sure you produce a build and keep the
pdb files around. Don't misplace these!

Next up, install the Debugging Tools for Windows - specifically, ADPlus. You
want to now configure AD Plus to generate a Mini-Dump file on a 2nd Chance
Exception of your process. This way you app will run just fine for a month,
and when it does crash, you'll get a dump file.From here, you need to use
WinDbg & Son of Strike to track down the exact cause of the problem.

I go through this in much more detail in a Blog Entry that I did a few
months back:
http://www.coversant.net/Default.asp...=88&EntryID=28

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, MVP C#
http://www.coversant.net/blogs/cmullins

<bj*****@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
The application i build in C#.net is crashing once a month. I can't
reproduce the crash.

Is there a way to track down where the program crashes, without
putting logging everywhere in the code? Is there a way to get a stack
trace of the crashing program (by the way, i'm new to C#.net, i have
experience in (unmanaged) C++).

Thanks in advance.

Feb 7 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
Greetings, Having a major problem here. running version 8.2 on win2003 server. The problem I am having is backing up a database seems to get to the last part of the backup and then fails. This...
14
by: Jurgen Haan | last post by:
Hey all, at the company where I work we had a strange situation yesterday. Our DB2 database locked up, or as it later seemed, the DBM, or some connection manager. We couldn't open new...
3
by: Me | last post by:
I'm getting a NullReferenceException in Unknown Module when I follow the below steps to create a simple NotifyIcon app that creates the context menu on the fly(see a little analysis after the...
3
by: Steve Franks | last post by:
I'm using Visual Studio 2005 RC and cannot figure out how to produce a "release" build. Am I doing something wrong? I'm wondering if perhaps MS locked out the ability to produce a release build...
6
by: George M. Garner Jr. | last post by:
VC8.0 crashes while compiling boost-1.33.1 serialization library (or any other library that includes the serialization headers) if code analysis (/analyze) is enabled. This problem did not occur...
2
by: kevinding | last post by:
Hi All, We meet an evil condition for our project. Our project has 3 layers. A C# layer to do some business logic, and Managed C++ layer translate managed values to native ones or vice...
1
by: kurt sune | last post by:
I am having trouble publishing a website for RELEASE. 1. web.config: <compilation defaultLanguage="vb" debug="false"> 2. in Configuration manager I set the configuration to Release for the...
8
by: Abubakar | last post by:
Hi, I want to know that when my application is running outside of the debugger (in debug or release build) can I set the application/project settings in a way that when it crashes it tells me...
1
by: Duncan Smith | last post by:
Hi All, Grateful if anyone has any suggestions here? I have a VS2005 MFC app which hosts several types of views in CFrameWnds - one of which contains a managed control hosted in a CWinFormsView...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.