views:

1224

answers:

10

I could use some help trying to track down an intermittent error that I've been having with our ASP.Net project for quite some time.

Intermittently when building the solution, the build will fail with the error "/: Build (web): Object reference not set to an instance of an object." The error has no associated file, line, column or project information. The weird thing about the error is that it will go away on successive rebuilds and doesn't seem to result in any run-time errors that we've come across once the build is successful. Sometimes the error will pop only once, sometimes 3-4 times, but eventually the build will finish successfully and then seems to build just fine each time after. I haven't been able to nail down a pattern as to why and when the error will happen, and since it always eventually builds it hasn't been a critical problem for us. Just an annoyance. But one that I want gone for obvious reasons.

I guess I should add that this is an application that was originally developed in ASP.net 1.1 and converted to 2.0 and I inherited it somewhere down the line after that, so I don't know when the problem originally surfaced. As far as everyone here is concerned, it's always been there.

Obviously I'm not expecting someone to pick out the cause of my problem as that would require them to look at our entire solution to pick out potential problems. Just hoping someone can give me a couple fresh ideas as to how to go about tracking down the actual source of the error in code. It has to be coming from somewhere, right? How would you go about finding out where?

A: 

An "Object reference not set to an instance of an object" is clearly a run-time error, not a compile-time error. So what that says to me is that Visual Studio is choking on something, which may not necessarily be in your code, or which something in your code is only indirectly causing.

Next question I'd ask: Does this happen only in Visual Studio, or does the same thing show up when you build using MSBuild or CSC?

DannySmurf
I haven't tried using MSBuild yet, but that's definitely something to do to figure out if the problem is with Visual Studio or not.
A: 

What's really odd is that it's a run-time error. You shouldn't see that at compile time. Do you have any pre- or post- build steps attached to the solution? Any unit tests you're including with your 'build' process?

Where does this error show up?

Joel Coehoorn
No pre or post build steps or unit tests. The error shows up in the middle of the build process at the same spot every time. The Output window lists all the directories it is building and then just throws that error. A following successful build eventually "gets past" that spot.
A: 

Check the Application Log of your Event Viewer - It should tell you where the exception is being thrown.

Nothing is showing up in the Application Log in Event Viewer related to this problem.
A: 

Just to clarify, is it the compiler itself that is choking? Are you doing anything weird with #define and #if directives in your code? Maybe something is being done out of order at some point... Just a thought...

A: 
  • See if there are any post-build events that could be failing. These can be found on each project's property page.

  • Try using Rebuild Solution instead of Build Solution. You may need to add Rebuild Solution from Tools > Customize. If your web app installs or registers any windows services, and those services are started, Rebuilding plows through those types of problems.

+1  A: 

I've seen this when you have a web control in a page where there is invalid HTML. If your codebehind is trying to do something with the control, it won't be able to find it and will give you Object Reference... error at compile time. In my experience, it doesn't create a runtime error, and the project will build if the file in question is closed at the time of build. HTH, Good Luck!

JasonS
Hmm this could be it. I know we have a lot of HTML that doesn't validate at this point because it was written back in the 1.1 days. It might only happen when I have files open, but I'll have to test and see.
+1  A: 

Run this command at the command line and see if you get some more detailed information

%WINDIR%\Microsoft.NET\Framework\v3.5\msbuild.exe YourSolution.sln /v:n

Rob
+1  A: 

I had this at build time when my project contained custom datasources (my own objects returning collections) with compile errors (that is, my objects had errors).

You'll also get this error if you try and add a datasource and your project doesn't have any datasources in the project's root (e.g. if you've put all your datasource classes in a subfolder). The only solution I found was to create a datasource in the project's root.

Sorry not to be more precise, but there seems to be several things that can go wrong with datasources/objects at compile-time.

A: 

The first thing I'd try would be to increase the compiler verbosity. This can be set in the Visual Studio options - e.g. "Tools->Options->Projects and Solutions-Build and Run->MSBuild project build output verbosity" for VS2005. If you set it to diagnostic then it should tell you what it's doing at the time the exception is raised at the very least.

Stu Mackellar
+1  A: 

To follow up on this problem, we never did track down the origin of the error but it disappeared when we upgraded to Visual Studio 2008 and converted the project to a Web Application.

classicmfk