Hope someone can assist with this, it’s driving me crazy.
I have a class that inherits from a parent object and which overrides some of the methods of that object. The relevant code in one of the overrides looks like this (I’ve stripped out code that functions correctly):
public override void Initialise()
{
if (Url != null)
{
_logger.LogInfo("Initialising for file " + Url);
// call the base Initialise method
try
{
base.Initialise();
}
catch (Exception ex)
{
_logger.LogError("Error on initialise : ", ex);
}
}
}
The logger object writes to our application log database.
When it reaches this point in the code for the first time, it logs error on initalise, and gives me an object reference not set to instance of object error. But there’s no further information, no inner exception, and no line number.
I’m left wondering if there’s any way that base could possibly be null? It seems bizarre and unlikely but I’m at a loss to explain why there’s no further information and why the code has resisted all my attempts to get any more information out of it.
It’s on a live server so I can’t step through it, and I can’t replicate the error on a test server. If anyone has any ideas as to how I can get more detail on where and how its going wrong, it’d be deeply appreciated.
Cheers,
Matt
Answer to your question is no. Base cannot be null, because it is instantiated before child class (if you don’t call specific base type constructor, then default one is called just before child class constructor executed). Your error comes from
base.Initialize()method.