When I first launched this blog I found I was frequently getting the following error.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
IIS7Injector.InjectedContentStream.Write(Byte[] buffer, Int32 offset, Int32 count) +146
System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +265
System.Web.HttpResponse.FilterOutput() +80
System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +54
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
I'd get the error, and then my site would be down until I updated my assemblies (I'm sure just restarting my site would do the same thing, but since I don't have that access through my hosting provider replacing the assemblies did the trick).
So for the last few months I've been stumped. I tried putting try-catch blocks all over the place to see where it was. I thought it might be with my security validation code, nope. I checked my Views, no problems there. Once I had rules those two out, I really started trying to fish for anything that it could be. I thought it might be in my MVC routes, nope. I thought it might somewhere in my data layer. Nope. No matter where I looked for the cause of the error I couldn't find the problem.
Now as I was trying all of these things, I kept thinking what the heck is IIS 7 injecting? Well I did know that my free hosting account on GoDaddy had ads injected into my page. Could that be it? Well it could be, but I figured it couldn't hurt to go through my own code first.
As I eliminated section after section I really started to think it was GoDaddy's ad injection. Now I didn't want it to be, I mean it would be great if I could keep using the free hosting instead of going to a paid service. I scanned the internet, and found other people that had the same problem, but they didn't have any solution to the problem either.
It couldn't be the ad injection could it? *Sigh* So two days ago I went ahead and upgraded my service to a basic plan without ads.
Guess what....
I haven't seen the error message since.....
So if you're using the free Windows hosting on GoDaddy and you're getting an IIS7 injector null reference error, odds are its their Ad Injection that is causing the problem. Try upgrading to an ad free account, and if you stop getting it, join me in trying to get GoDaddy fix their bug so we can all go back to free web hosting.