473,796 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4804
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.goo glegroups.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.goo glegroups.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.Applicati on.ThreadExcept ion += new
ThreadException EventHandler(Ap plication_Threa dException);
// Set the unhandled exception mode to force all Windows Forms errors
to go through our handler.
System.Windows. Forms.Applicati on.SetUnhandled ExceptionMode(U nhandledExcepti onMode.CatchExc eption);
// Add the event handler for handling non-UI thread exceptions to the
event.
AppDomain.Curre ntDomain.Unhand ledException += new
UnhandledExcept ionEventHandler (CurrentDomain_ UnhandledExcept ion);

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

private static void Application_Thr eadException(ob ject sender,
ThreadException EventArgs e)
{
// e.Exception.Sta ckTrace 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.c om 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.c om 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.To String(); or
TheException.St ackTrace();

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.Diagnost ics.Trace.Liste ners.Add(
new System.Diagnost ics.EventLogTra ceListener(Appl ication.Product Name));

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.Tr aceVerbose)
Trace.TraceInfo rmation("Update d 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("Gl obal",
Application.Pro ductName + " Trace Switch");

[Conditional("TR ACE")]
public static void TraceVerbose(st ring format, params object[] args)
{
if (traceSwitch.Tr aceVerbose)
Trace.TraceInfo rmation(format, args);
}

[Conditional("TR ACE")]
public static void TraceVerbose(st ring message)
{
if (traceSwitch.Tr aceVerbose)
Trace.TraceInfo rmation(message );
}
}

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

Program.TraceVe rbose("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.goo glegroups.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.goo glegroups.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
5567
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 brings the whole instance down and it has to be restarted. In addition the job seems to be stuck in the TOOLSDB as if I try to delete the backup job I get "The task is currently running". So I went to the command line and tried "db2 backup database...
14
3565
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 connections to the database, but existing connections remained. So the instances were working fine. Also, I couldn't connect using IPC, so I was unable to shut the database
3
2112
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 steps). 1. Create a new Windows Forms C# solution (I called mine DBChanger). 2. Replace Form1.cs code with this: -------------------- using System;
3
2897
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 when using the RC since it does not have a go-live license? Or maybe I'm just doing something wrong. I do not want to go live with a release build. Rather I just want to test locally to see if there is a performance difference and also to...
6
1764
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 with prior beta releases of boost-1.33.1 or with the VC8.0 beta. You may want to consider whether the crash of a dependent tool should be allowed to cause the entire VC8 IDE to hang or whether this might be a design defect. Given the recent price...
2
3564
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 verse.(vs2005, /clr:oldSyntax) . UI layer are written in native C++. Currently, we meet a random crash bug in release build. It is ok in debug build. If we replace the managed c++ dll with the debug one, it works also. So we think there must be...
1
2998
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 website 3. in Configuration manager I set the Active solution configuration to Release
8
1790
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 which method of which class it was running while it crashed. And can it also give me the stack trace of when the crash happened? I'm asking this cuz I'm running the app in a machine in which I cant install the visual studio, but I do have the...
1
1696
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 Everything works well on my dev pc (and other peoples dev pcs), but when I try and instantiate the managed view on a target-pc (no compilers, etc) there's an exception thrown followed by program termination.
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10190
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.