[Mono-dev] Getting error at Runtime

mike.hull at coversant.net mike.hull at coversant.net
Sat Feb 11 01:43:26 EST 2006

Javier Ruiz wrote:
> I get the following error at runtime from the attached code.
> Object reference not set to an instance of an object
> I still don't understand why if I compile the code using VS 2005 and 
> run the program on windows it works but if I compile with gmcs and run 
> on Linux I get errors.
Is there a stack trace?

ex.ToString() should give you a better idea of what it is.

I think your problem is here:

       string sysdate = (string)dbreader["sysdate"].ToString();

If that dbreader["sysdate"] == null then you'll get a NRE.

Try this:
object sysdate = dbreader["sysdate"];
string sysdate = sysdate == null ? string.Empty : sysdate.ToString();

More information about the Mono-devel-list mailing list