Strange NullReference Exception for controls shown in Master page

Everyday the first thing I do before any dev work is to get latest code.  This morning the code updated, my web application doesn’t work; and started to give me a NullReferenceException complaining about a line which assign a text to a hyperlink control Page_Load event method.  It is strange, right? All controls should be initialized after Page_PreInit.  The control get complained is added recently.  And it works fine when I am running debug mode.

I tried to resolve it by:

  1. Do a clean build.
  2. IIS reset.
  3. Restart application pool.
  4. Restart machine.

However I have no luck to solve it.  Finally I think the compiled markup may be in an invalid state.  So what I did is put a space of the control id and then remove it; rebuild and test it again.  And it is fixed.  After investigation, it is about the cache of my master page is invalid (no idea why out-of-sync).  The solution is either making some changes on the markup page to trigger re-generation or you should go to corresponding ASP.Net temporary file folder (e.g. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root) and delete all folders.

Hope this will help!!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s