Click here to Skip to main content
15,886,052 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i m working on window application in C# 2.0 this application is so large and i m working on one module.

the exception at run time is:-
"Object Reference not set to an instance of an object".

i m confuse, from where it is generate and why it is generated, because the solution has no error at compile time and also the data is saved to the database but could not fetch when click on the result button for that data.



Please help me.
thanks!
Posted
Comments
Toniyo Jackson 16-Mar-11 7:50am    
Debug using break points and find where is the problem? No other way...
Sharma Richa 16-Mar-11 7:52am    
You can check it by adding break points on your page
Sergey Alexandrovich Kryukov 16-Mar-11 14:28pm    
OP commented:

hi thanks all for reply

as u said i have used try catch and debug the application so many times and didn't get the exception because memory deadlock occur because this is very large and complicated project and so many API's is used in it.
and i m new to this project, this project started 3 years ago and till not completed.
that's the reason i m worried about.

and not get from where this exception occur.

so please suggest me the other ways of finding this exception.

Thanks
Sergey Alexandrovich Kryukov 16-Mar-11 14:29pm    
See my directions in my Answer; you will learn how to capture and report those exceptions.
--SA

Have you run your app under the debugger yet? It's a free tool that comes with Visual Studio.
 
Share this answer
 
OK, so add a breakpoint to the 'result button' click event handler. Now step through your code until the error occurs

Compile time and Run time errors are very different things!
 
Share this answer
 
This it what happen when you try to use a reference that is not set to a valid instance of an object - ie. a null reference.

The following may be helpful when you wish to track down null references, and other exceptions, when running a program under a debugger. It's particularly useful when you are working with code written by others, and trying to figure things out :)

AppDomain has two interesting events:
AppDomain.FirstChanceException Event[^]
and
AppDomain.UnhandledException Event[^]

So you can write
static void FirstChanceHandler(object source, FirstChanceExceptionEventArgs e)
{
#if DEBUG
 if (System.Diagnostics.Debugger.IsAttached)
 {
  System.Diagnostics.Debugger.Break();
 }
#endif
}


And then assign the handler in your Main method
static void Main()
{
 AppDomain.CurrentDomain.FirstChanceException += FirstChanceHandler;
 // the rest of the Main method ...
}


Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Mar-11 18:16pm    
Wow. This is something I need to learn! Thank you very much, 5++++++++++++++++++++
--SA
Espen Harlinn 16-Mar-11 18:41pm    
Thanks SAKryukov!
Albin Abel 16-Mar-11 23:08pm    
Using App Domains is a neglected among programmers, but more powerful. Thanks for highlighting its uses. My 5++++
Espen Harlinn 17-Mar-11 7:11am    
Thanks AlbinAbel!
Balwant.mnd 17-Mar-11 0:23am    
thanks Espen Harlinn
thank you very much.
Use debugger as John already advised. For code project report, please use my directions from past Answers:

How do i make a loop that will stop when a scrollbar reaches the bottom[^]
When i run an application an exception is caught how to handle this?[^]

—SA
 
Share this answer
 
Comments
Espen Harlinn 16-Mar-11 17:48pm    
5ed!
Sergey Alexandrovich Kryukov 16-Mar-11 18:49pm    
Thank you.
--SA
Hope you are using exception handlers like try, catch.. In that case, put the break points for the functions where you are getting the error and then debug ur application... You can't fix this issue, until and unless u follow debugging with break point/s...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900