Dave Burke - Freelance .NET Developer specializing in Online Communities

A freelance .NET Developer

Object reference instance error and the web.config

Problem

Your app is looking for an appsetting value in the web.config and when it isn't found generates the error 

Object reference not set to an instance of an object.

Resolution

Add the friggen' appsetting value

Analysis

Wooo-wee!  This is a humdinger of a tough bug to track down.  Usually you'll have pretty clear information in the stack to pinpoint the missing object, or it may be something as obvious as a Label webcontrol missing in the .ASPX.  But there's very little to go on when its a missing appsetting value.  This error generally appears when testing a new app on a production server after updating the /bin/dlls, which is a bad thing.  This also makes diagnosis more difficult, so a documented procedure to update the server web.config prior to updating the dlls is a good thing.

For more information

See comments.

Comments

Karl said:

The ASP.Net 2.0 forums use a custom SectionHandler which I find helps elimiate a lot of problems with web.config. For your case it would isolate the loading of values to specific function, which would help debug. you might want to take a look at what they do.
# April 27, 2004 1:14 PM

Dave Burke said:

SectionHandler? Good idea. Thanks, Karl! I will investigate.
# April 27, 2004 2:02 PM

Phil Winstanley said:

That error is a pain in the ass wherever it occurs, could it really be that hard to go: -

Object reference (<THE OBJECT NAME>) not set to an instance of an object.

:)
# April 27, 2004 2:14 PM

Dave Burke said:

Phil, from experience I've learned to keep my expectations pretty low. Yes, that's a great idea.
# April 27, 2004 2:20 PM

Travis said:

Someone at MSDN expained in a blog article why they had to make this Exception so generic. Damn, I wish I could find it. I'll keep searching.
# April 27, 2004 4:54 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)