Visual Studio .Net 2003 constant "object reference not set..."
- From: Xanthus <Xanthus@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 07:29:54 -0800
I have a problem with a C# WinForms project. Just loading the solution
produces a message box from Visual Studio saying "object reference not set to
instance of an object". I put about 20 try/catch blocks in to locate the
exact line of code that causes the message. I am now getting a specific error
message I created.
The application uses Form1 to create/show Form2 by user button click. Form2
contains UserControl1. The code is executed in the User Control (named
CreditorEdit) Load event. The code is below.
Obviously, VS thinks variable dt (DataTable) or dt.Rows is not set. Well
sure, since it's set from a database call, and the database parameter
(_currentCreditorID) will be set.
WHY IS IT THROWING THIS ERROR WHEN LOADING THE SOLUTION. This is highly
irritating. I can ignore it since I know it runs ok, but what about the next
programmer to pull this code from SourceSafe and try it. They will think
there is an error.
// USER CONTROL
private void CreditorEdit_Load(object sender, System.EventArgs e)
{
try
{
LoadStyleSheets();
}
catch(Exception ex)
{
MessageBox.Show("UserControl Load : " +
ex.Message,_MSGBOX_CAPTION,MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
throw ex;
}
}
private void LoadStyleSheets()
{
DataTable dt;
try
{
// _currentCreditor id set by parent after construction, defaulted to 0
// on construction, which tells the CreditorSettings object not to try
// database call. I tried defaulting it to -1, so VS would see a DB
call, but
// I STILL get the error message
_CreditorSettings = new CreditorSettings(_currentCreditorId);
}
catch(Exception ex)
{
MessageBox.Show("CreditorEdit LoadStyleSheets CreditorSettings: " +
ex.Message,_MSGBOX_CAPTION,MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
throw ex;
}
// now get the DataTable we are interested in
try
{
//dt = new DataTable();
dt = _CreditorSettings.CreditorStyles;
if(dt.Rows.Count > 0)
{
...
}
catch(Exception ex)
{
// THIS IS THE ERROR MESSAGE SHOWN BY VISUAL STUDIO WHEN THE
// SOLUTION IS LOADED. WHY??????
MessageBox.Show("CreditorEdit LoadStyleSheets CreditorStyles: " +
ex.Message,_MSGBOX_CAPTION,MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
throw ex;
}
}
.
- Prev by Date: RE: How to debug remotely and ensure that the loaded assemblies are re
- Previous by thread: RE: How to debug remotely and ensure that the loaded assemblies are re
- Index(es):
Loading